comform source code width

This commit is contained in:
Evan You 2014-08-10 14:12:22 -04:00
parent d4accea3c6
commit 779ec3417f
22 changed files with 224 additions and 147 deletions

View File

@ -18,8 +18,8 @@ exports.$get = function (exp) {
/** /**
* Set the value from an expression on this vm. * Set the value from an expression on this vm.
* The expression must be a valid left-hand expression * The expression must be a valid left-hand
* in an assignment. * expression in an assignment.
* *
* @param {String} exp * @param {String} exp
* @param {*} val * @param {*} val
@ -33,7 +33,8 @@ exports.$set = function (exp, val) {
} }
/** /**
* Add a property on the VM (and also on $scope and $data) * Add a property on the VM
* (and also on $scope and $data)
* *
* @param {String} key * @param {String} key
* @param {*} val * @param {*} val
@ -44,7 +45,8 @@ exports.$add = function (key, val) {
} }
/** /**
* Delete a property on the VM (and also on $scope and $data) * Delete a property on the VM
* (and also on $scope and $data)
* *
* @param {String} key * @param {String} key
*/ */
@ -54,8 +56,9 @@ exports.$delete = function (key) {
} }
/** /**
* Watch an expression, trigger callback when its value changes. * Watch an expression, trigger callback when its
* Returns the created watcher's id so it can be teardown later. * value changes. Returns the created watcher's
* id so it can be teardown later.
* *
* @param {String} exp * @param {String} exp
* @param {Function} cb * @param {Function} cb
@ -86,6 +89,7 @@ exports.$unwatch = function (id) {
* Interpolate a piece of template string. * Interpolate a piece of template string.
* *
* @param {String} string * @param {String} string
* @return {String}
*/ */
exports.$interpolate = function (string) { exports.$interpolate = function (string) {

View File

@ -7,7 +7,10 @@
? 'applyEmit' ? 'applyEmit'
: method : method
exports['$' + method] = function () { exports['$' + method] = function () {
this._emitter[realMethod].apply(this._emitter, arguments) this._emitter[realMethod].apply(
this._emitter,
arguments
)
} }
}) })
@ -22,8 +25,14 @@ exports.$broadcast = function () {
var children = this.children var children = this.children
for (var i = 0, l = children.length; i < l; i++) { for (var i = 0, l = children.length; i < l; i++) {
var child = children[i] var child = children[i]
child._emitter.applyEmit.apply(child._emitter, arguments) child._emitter.applyEmit.apply(
child.$broadcast.apply(child, arguments) child._emitter,
arguments
)
child.$broadcast.apply(
child,
arguments
)
} }
} }
@ -35,9 +44,15 @@ exports.$broadcast = function () {
*/ */
exports.$dispatch = function () { exports.$dispatch = function () {
this._emitter.applyEmit.apply(this._emitter, arguments) this._emitter.applyEmit.apply(
this._emitter,
arguments
)
var parent = this.$parent var parent = this.$parent
if (parent) { if (parent) {
parent.$dispatch.apply(parent, arguments) parent.$dispatch.apply(
parent,
arguments
)
} }
} }

View File

@ -8,9 +8,9 @@ var assetTypes = [
] ]
/** /**
* Vue and every constructor that extends Vue has an associated * Vue and every constructor that extends Vue has an
* options object, which can be accessed during compilation steps * associated options object, which can be accessed during
* as `this.constructor.options`. * compilation steps as `this.constructor.options`.
*/ */
exports.options = { exports.options = {

View File

@ -1,7 +1,8 @@
/** /**
* Set instance target element and kick off the compilation process. * Set instance target element and kick off the compilation
* The passed in `el` can be a selector string, an existing Element, * process. The passed in `el` can be a selector string, an
* or a DocumentFragment (for block instances). * existing Element, or a DocumentFragment (for block
* instances).
* *
* @param {Element|DocumentFragment|string} el * @param {Element|DocumentFragment|string} el
* @public * @public

View File

@ -1,7 +1,7 @@
/** /**
* A binding is an observable that can have multiple directives * A binding is an observable that can have multiple
* subscribing to it. It can also have multiple other bindings * directives subscribing to it. It can also have multiple
* as children to form a trie-like structure. * other bindings as children to form a trie-like structure.
* *
* All binding properties are prefixed with `_` so that they * All binding properties are prefixed with `_` so that they
* don't conflict with children keys. * don't conflict with children keys.

View File

@ -1,8 +1,9 @@
/** /**
* A doubly linked list-based Least Recently Used (LRU) cache. * A doubly linked list-based Least Recently Used (LRU)
* Will keep most recently used items while discarding least * cache. Will keep most recently used items while
* recently used items when its limit is reached. This is a * discarding least recently used items when its limit is
* bare-bone version of Rasmus Andersson's js-lru: * reached. This is a bare-bone version of
* Rasmus Andersson's js-lru:
* *
* https://github.com/rsms/js-lru * https://github.com/rsms/js-lru
* *
@ -51,8 +52,9 @@ p.put = function (key, value) {
} }
/** /**
* Purge the least recently used (oldest) entry from the cache. * Purge the least recently used (oldest) entry from the
* Returns the removed entry or undefined if the cache was empty. * cache. Returns the removed entry or undefined if the
* cache was empty.
*/ */
p.shift = function () { p.shift = function () {

View File

@ -2,10 +2,10 @@ var _ = require('./util')
var Watcher = require('./watcher') var Watcher = require('./watcher')
/** /**
* A directive links a DOM element with a piece of data, which can * A directive links a DOM element with a piece of data,
* be either simple paths or computed properties. It subscribes to * which is the result of evaluating an expression.
* a list of dependencies (Bindings) and refreshes the list during * It registers a watcher with the expression and calls
* its getter evaluation. * the DOM update function when a change is triggered.
* *
* @param {String} name * @param {String} name
* @param {Node} el * @param {Node} el
@ -113,7 +113,8 @@ p._teardown = function () {
/** /**
* Set the corresponding value with the setter. * Set the corresponding value with the setter.
* This should only be used in two-way bindings like v-model. * This should only be used in two-way directives
* e.g. v-model.
* *
* @param {*} value * @param {*} value
* @param {Boolean} lock - prevent wrtie triggering update. * @param {Boolean} lock - prevent wrtie triggering update.

View File

@ -5,18 +5,13 @@ var Observer = require('../observe/observer')
/** /**
* Setup the binding tree. * Setup the binding tree.
* *
* Bindings form a tree-like structure that maps the Object structure * Bindings form a tree-like structure that maps the Object
* of observed data. However, only paths present in the templates are * structure of observed data. However, only paths present
* created in the binding tree. When a change event from the data * in the templates are created in the binding tree. When a
* observer arrives on the instance, we traverse the binding tree * change event from the data observer arrives on the
* along the changed path, triggering binding updates along the way. * instance, we traverse the binding tree along the changed
* When we reach the path endpoint, if it has any children, we also * path to find the corresponding binding, and trigger
* trigger updates on the entire sub-tree. * change for all its subscribers.
*
* Each instance has a root binding and it has three special children:
* `$data`, `$parent` & `$root`. `$data` points to the root binding
* itself. `$parent` and `$root` point to the instance's parent and
* root's root bindings, respectively.
*/ */
exports._initBindings = function () { exports._initBindings = function () {
@ -90,11 +85,12 @@ exports._updateBindingAt = function (path) {
} }
/** /**
* For newly added properties, since its binding has not been * For newly added properties, since its binding has not
* created yet, directives will not have it as a dependency yet. * been created yet, directives will not have it as a
* However, they will have its parent as a dependency. Therefore * dependency yet. However, they will have its parent as a
* here we remove the last segment from the path and notify the * dependency. Therefore here we remove the last segment
* added property's parent instead. * from the path and notify the added property's parent
* instead.
* *
* @param {String} path * @param {String} path
*/ */
@ -106,7 +102,8 @@ exports._updateAdd = function (path) {
} }
/** /**
* Collect dependency for the target directive being evaluated. * Collect dependency for the target directive being
* evaluated.
* *
* @param {String} path * @param {String} path
*/ */

View File

@ -18,10 +18,10 @@ exports._initElement = function (el) {
_.warn('Cannot find element: ' + selector) _.warn('Cannot find element: ' + selector)
} }
} }
// If the passed in `el` is a DocumentFragment, the instance is // If the passed in `el` is a DocumentFragment, the
// considered a "block instance" which manages not a single element, // instance is considered a "block instance" which manages
// but multiple elements. A block instance's `$el` is an Array of // not a single element, but multiple elements. A block
// the elements it manages. // instance's `$el` is an Array of the elements it manages.
if (el instanceof window.DocumentFragment) { if (el instanceof window.DocumentFragment) {
this._isBlock = true this._isBlock = true
this.$el = _.toArray(el.childNodes) this.$el = _.toArray(el.childNodes)
@ -34,7 +34,7 @@ exports._initElement = function (el) {
/** /**
* Process the template option. * Process the template option.
* If the replace option is true this will also modify the $el. * If the replace option is true this will swap the $el.
*/ */
exports._initTemplate = function () { exports._initTemplate = function () {
@ -46,7 +46,7 @@ exports._initTemplate = function () {
if (!frag) { if (!frag) {
_.warn('Invalid template option: ' + template) _.warn('Invalid template option: ' + template)
} else { } else {
// collect raw content. this wipes out the container el. // collect raw content. this wipes out $el.
this._collectRawContent() this._collectRawContent()
frag = frag.cloneNode(true) frag = frag.cloneNode(true)
if (options.replace) { if (options.replace) {
@ -93,10 +93,10 @@ exports._collectRawContent = function () {
} }
/** /**
* Resolve <content> insertion points per W3C Web Components * Resolve <content> insertion points mimicking the behavior
* working draft: * of the Shadow DOM spec:
* *
* http://www.w3.org/TR/2013/WD-components-intro-20130606/#insertion-points * http://w3c.github.io/webcomponents/spec/shadow/#insertion-points
*/ */
exports._initContent = function () { exports._initContent = function () {
@ -112,7 +112,9 @@ exports._initContent = function () {
if (raw) { if (raw) {
select = outlet.getAttribute('select') select = outlet.getAttribute('select')
if (select) { // select content if (select) { // select content
outlet.content = _.toArray(raw.querySelectorAll(select)) outlet.content = _.toArray(
raw.querySelectorAll(select)
)
} else { // default content } else { // default content
main = outlet main = outlet
} }
@ -142,7 +144,6 @@ exports._initContent = function () {
*/ */
var concat = [].concat var concat = [].concat
function getOutlets (el) { function getOutlets (el) {
return _.isArray(el) return _.isArray(el)
? concat.apply([], el.map(getOutlets)) ? concat.apply([], el.map(getOutlets))
@ -150,7 +151,8 @@ function getOutlets (el) {
} }
/** /**
* Insert an array of nodes at outlet, then remove the outlet. * Insert an array of nodes at outlet,
* then remove the outlet.
* *
* @param {Element} outlet * @param {Element} outlet
* @param {Array} contents * @param {Array} contents

View File

@ -13,8 +13,8 @@ exports._initEvents = function () {
for (e in events) { for (e in events) {
handlers = events[e] handlers = events[e]
for (i = 0, j = handlers.length; i < j; i++) { for (i = 0, j = handlers.length; i < j; i++) {
var handler = (methods && typeof handlers[i] === 'string') var handler = typeof handlers[i] === 'string'
? methods[handlers[i]] ? methods && methods[handlers[i]]
: handlers[i] : handlers[i]
this.$on(e, handler) this.$on(e, handler)
} }

View File

@ -2,13 +2,14 @@ var Emitter = require('../emitter')
var mergeOptions = require('../util').mergeOptions var mergeOptions = require('../util').mergeOptions
/** /**
* The main init sequence. This is called for every instance, * The main init sequence. This is called for every
* including ones that are created from extended constructors. * instance, including ones that are created from extended
* constructors.
* *
* @param {Object} options - this options object should be the * @param {Object} options - this options object should be
* result of merging class options * the result of merging class
* and the options passed in to the * options and the options passed
* constructor. * in to the constructor.
*/ */
exports._init = function (options) { exports._init = function (options) {
@ -39,8 +40,8 @@ exports._init = function (options) {
this this
) )
// the `created` hook is called after basic properties have // the `created` hook is called after basic properties
// been set up & before data observation happens. // have been set up & before data observation happens.
this._callHook('created') this._callHook('created')
// create scope. // create scope.

View File

@ -6,7 +6,8 @@ var scopeEvents = ['set', 'mutate', 'add', 'delete']
* Setup instance scope. * Setup instance scope.
* The scope is reponsible for prototypal inheritance of * The scope is reponsible for prototypal inheritance of
* parent instance propertiesm abd all binding paths and * parent instance propertiesm abd all binding paths and
* expressions of the current instance are evaluated against its scope. * expressions of the current instance are evaluated against
* its scope.
* *
* This should only be called once during _init(). * This should only be called once during _init().
*/ */
@ -64,20 +65,22 @@ exports._teardownScope = function () {
/** /**
* Setup the instances data object. * Setup the instances data object.
* *
* Properties are copied into the scope object to take advantage of * Properties are copied into the scope object to take
* prototypal inheritance. * advantage of prototypal inheritance.
* *
* If the `syncData` option is true, Vue will maintain property * If the `syncData` option is true, Vue will maintain
* syncing between the scope and the original data object, so that * property syncing between the scope and the original data
* any changes to the scope are synced back to the passed in object. * object, so that any changes to the scope are synced back
* This is useful internally when e.g. creating v-repeat instances * to the passed in object. This is useful internally when
* with no alias. * e.g. creating v-repeat instances with no alias.
* *
* If swapping data object with the `$data` accessor, teardown * If swapping data object with the `$data` accessor,
* previous sync listeners and delete keys not present in new data. * teardown previous sync listeners and delete keys not
* present in new data.
* *
* @param {Object} data * @param {Object} data
* @param {Boolean} init - if not ture, indicates its a `$data` swap. * @param {Boolean} init - if not ture, indicates its a
* `$data` swap.
*/ */
exports._initData = function (data, init) { exports._initData = function (data, init) {
@ -120,13 +123,13 @@ exports._initData = function (data, init) {
* Proxy the scope properties on the instance itself, * Proxy the scope properties on the instance itself,
* so that vm.a === vm.$scope.a. * so that vm.a === vm.$scope.a.
* *
* Note this only proxies *local* scope properties. We want to * Note this only proxies *local* scope properties. We want
* prevent child instances accidentally modifying properties * to prevent child instances accidentally modifying
* with the same name up in the scope chain because scope * properties with the same name up in the scope chain
* perperties are all getter/setters. * because scope perperties are all getter/setters.
* *
* To access parent properties through prototypal fall through, * To access parent properties through prototypal fall
* access it on the instance's $scope. * through, access it on the instance's $scope.
* *
* This should only be called once during _init(). * This should only be called once during _init().
*/ */

View File

@ -27,8 +27,8 @@ var OBJECT = 1
* @param {Array|Object} value * @param {Array|Object} value
* @param {Number} type * @param {Number} type
* @param {Object} [options] * @param {Object} [options]
* - doNotAlterProto: if true, do not alter object's __proto__ * - doNotAlterProto
* - callbackContext: `this` context for callbacks * - callbackContext
*/ */
function Observer (value, type, options) { function Observer (value, type, options) {
@ -90,15 +90,19 @@ Observer.create = function (value, options) {
return value.$observer return value.$observer
} if (_.isArray(value)) { } if (_.isArray(value)) {
return new Observer(value, ARRAY, options) return new Observer(value, ARRAY, options)
} else if (_.isObject(value) && !value.$scope) { // avoid Vue instance } else if (
_.isObject(value) &&
!value.$scope // avoid Vue instance
) {
return new Observer(value, OBJECT, options) return new Observer(value, OBJECT, options)
} }
} }
/** /**
* Walk through each property, converting them and adding them as child. * Walk through each property, converting them and adding
* This method should only be called when value type is Object. * them as child. This method should only be called when
* Properties prefixed with `$` or `_` and accessor properties are ignored. * value type is Object. Properties prefixed with `$` or `_`
* and accessor properties are ignored.
* *
* @param {Object} obj * @param {Object} obj
*/ */

View File

@ -58,8 +58,8 @@ function pushFilter () {
} }
/** /**
* Parse a directive string into an Array of AST-like objects * Parse a directive string into an Array of AST-like
* representing directives. * objects representing directives.
* *
* Example: * Example:
* *
@ -86,7 +86,8 @@ exports.parse = function (s) {
// reset parser state // reset parser state
str = s str = s
inSingle = inDouble = false inSingle = inDouble = false
curly = square = paren = begin = argIndex = lastFilterIndex = 0 curly = square = paren = begin = argIndex = 0
lastFilterIndex = 0
dirs = [] dirs = []
dir = {} dir = {}
arg = null arg = null
@ -99,13 +100,20 @@ exports.parse = function (s) {
} else if (inDouble) { } else if (inDouble) {
// check double quote // check double quote
if (c === '"') inDouble = !inDouble if (c === '"') inDouble = !inDouble
} else if (c === ',' && !paren && !curly && !square) { } else if (
c === ',' &&
!paren && !curly && !square
) {
// reached the end of a directive // reached the end of a directive
pushDir() pushDir()
// reset & skip the comma // reset & skip the comma
dir = {} dir = {}
begin = argIndex = lastFilterIndex = i + 1 begin = argIndex = lastFilterIndex = i + 1
} else if (c === ':' && !dir.expression && !dir.arg) { } else if (
c === ':' &&
!dir.expression &&
!dir.arg
) {
// argument // argument
arg = str.slice(begin, i).trim() arg = str.slice(begin, i).trim()
// test for valid argument here // test for valid argument here
@ -119,7 +127,11 @@ exports.parse = function (s) {
? arg.slice(1, -1) ? arg.slice(1, -1)
: arg : arg
} }
} else if (c === '|' && str.charAt(i + 1) !== '|' && str.charAt(i - 1) !== '|') { } else if (
c === '|' &&
str.charAt(i + 1) !== '|' &&
str.charAt(i - 1) !== '|'
) {
if (dir.expression === undefined) { if (dir.expression === undefined) {
// first filter, end of expression // first filter, end of expression
lastFilterIndex = i + 1 lastFilterIndex = i + 1

View File

@ -3,26 +3,36 @@ var Path = require('./path')
var Cache = require('../cache') var Cache = require('../cache')
var expressionCache = new Cache(1000) var expressionCache = new Cache(1000)
var keywords =
'Math,break,case,catch,continue,debugger,default,' +
'delete,do,else,false,finally,for,function,if,in,' +
'instanceof,new,null,return,switch,this,throw,true,try,' +
'typeof,var,void,while,with,undefined,abstract,boolean,' +
'byte,char,class,const,double,enum,export,extends,' +
'final,float,goto,implements,import,int,interface,long,' +
'native,package,private,protected,public,short,static,' +
'super,synchronized,throws,transient,volatile,' +
'arguments,let,yield'
var wsRE = /\s/g var wsRE = /\s/g
var newlineRE = /\n/g var newlineRE = /\n/g
var saveRE = /[\{,]\s*[\w\$_]+\s*:|'[^']*'|"[^"]*"/g var saveRE = /[\{,]\s*[\w\$_]+\s*:|'[^']*'|"[^"]*"/g
var restoreRE = /"(\d+)"/g var restoreRE = /"(\d+)"/g
var pathTestRE = /^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\])*$/ var pathTestRE = /^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\])*$/
var pathReplaceRE = /[^\w$\.]([A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\])*)/g var pathReplaceRE = /[^\w$\.]([A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\])*)/g
var keywords = 'Math,break,case,catch,continue,debugger,default,delete,do,else,false,finally,for,function,if,in,instanceof,new,null,return,switch,this,throw,true,try,typeof,var,void,while,with,undefined,abstract,boolean,byte,char,class,const,double,enum,export,extends,final,float,goto,implements,import,int,interface,long,native,package,private,protected,public,short,static,super,synchronized,throws,transient,volatile,arguments,let,yield'
var keywordsRE = new RegExp('^(' + keywords.replace(/,/g, '\\b|') + '\\b)') var keywordsRE = new RegExp('^(' + keywords.replace(/,/g, '\\b|') + '\\b)')
// note the following regex is only used on valid paths var rootPathRE = /^[\w$]+/ // this is only used on valid
// so no need to exclude number for first char // paths so no need to exclude
var rootPathRE = /^[\w$]+/ // number for first char
/** /**
* Save / Rewrite / Restore * Save / Rewrite / Restore
* *
* When rewriting paths found in an expression, it is possible * When rewriting paths found in an expression, it is
* for the same letter sequences to be found in strings and Object * possible for the same letter sequences to be found in
* literal property keys. Therefore we remove and store these * strings and Object literal property keys. Therefore we
* parts in a temporary array, and restore them after the path * remove and store these parts in a temporary array, and
* rewrite. * restore them after the path rewrite.
*/ */
var saved = [] var saved = []
@ -84,8 +94,8 @@ function restore (str, i) {
} }
/** /**
* Rewrite an expression, prefixing all path accessors with `scope.` * Rewrite an expression, prefixing all path accessors with
* and generate getter/setter functions. * `scope.` and generate getter/setter functions.
* *
* @param {String} exp * @param {String} exp
* @param {Boolean} needSet * @param {Boolean} needSet
@ -151,8 +161,8 @@ function compilePathFns (exp) {
/** /**
* Build a getter function. Requires eval. * Build a getter function. Requires eval.
* *
* We isolate the try/catch so it doesn't affect the optimization * We isolate the try/catch so it doesn't affect the
* of the parse function when it is not called. * optimization of the parse function when it is not called.
* *
* @param {String} body * @param {String} body
* @return {Function|undefined} * @return {Function|undefined}
@ -162,7 +172,10 @@ function makeGetter (body) {
try { try {
return new Function('scope', 'return ' + body + ';') return new Function('scope', 'return ' + body + ';')
} catch (e) { } catch (e) {
_.warn('Invalid expression. Generated function body: ' + body) _.warn(
'Invalid expression. ' +
'Generated function body: ' + body
)
} }
} }
@ -182,7 +195,11 @@ function makeGetter (body) {
function makeSetter (body) { function makeSetter (body) {
try { try {
return new Function('scope', 'value', body + ' = value;') return new Function(
'scope',
'value',
body + ' = value;'
)
} catch (e) { } catch (e) {
_.warn('Invalid setter function body: ' + body) _.warn('Invalid setter function body: ' + body)
} }
@ -201,7 +218,7 @@ function checkSetter (hit) {
} }
/** /**
* Parse an expression and rewrite into a getter/setter functions * Parse an expression into re-written getter/setters.
* *
* @param {String} exp * @param {String} exp
* @param {Boolean} needSet * @param {Boolean} needSet
@ -218,9 +235,9 @@ exports.parse = function (exp, needSet) {
} }
return hit return hit
} }
// we do a simple path check to optimize for that scenario. // we do a simple path check to optimize for them.
// the check fails valid paths with unusal whitespaces, but // the check fails valid paths with unusal whitespaces,
// that's too rare and we don't care. // but that's too rare and we don't care.
var res = pathTestRE.test(exp) var res = pathTestRE.test(exp)
? compilePathFns(exp) ? compilePathFns(exp)
: compileExpFns(exp, needSet) : compileExpFns(exp, needSet)

View File

@ -140,7 +140,8 @@ function getPathCharType (char) {
function parsePath (path) { function parsePath (path) {
var keys = [] var keys = []
var index = -1 var index = -1
var c, newChar, key, type, transition, action, typeMap, mode = 'beforePath' var mode = 'beforePath'
var c, newChar, key, type, transition, action, typeMap
var actions = { var actions = {
push: function() { push: function() {
@ -188,7 +189,9 @@ function parsePath (path) {
mode = transition[0] mode = transition[0]
action = actions[transition[1]] || noop action = actions[transition[1]] || noop
newChar = transition[2] === undefined ? c : transition[2] newChar = transition[2] === undefined
? c
: transition[2]
action() action()
if (mode === 'afterPath') { if (mode === 'afterPath') {

View File

@ -37,8 +37,8 @@ var TAG_RE = /<([\w:]+)/
/** /**
* Convert a string template to a DocumentFragment. * Convert a string template to a DocumentFragment.
* Determines correct wrapping by tag types. Wrapping strategy * Determines correct wrapping by tag types. Wrapping
* originally from jQuery, scooped from component/domify. * strategy found in jQuery & component/domify.
* *
* @param {String} templateString * @param {String} templateString
* @return {DocumentFragment} * @return {DocumentFragment}
@ -56,7 +56,9 @@ function stringToFragment (templateString) {
if (!tagMatch) { if (!tagMatch) {
// text only, return a single text node. // text only, return a single text node.
frag.appendChild(document.createTextNode(templateString)) frag.appendChild(
document.createTextNode(templateString)
)
} else { } else {
var tag = tagMatch[1] var tag = tagMatch[1]
@ -93,7 +95,10 @@ function nodeToFragment (node) {
var tag = node.tagName var tag = node.tagName
// if its a template tag and the browser supports it, // if its a template tag and the browser supports it,
// its content is already a document fragment. // its content is already a document fragment.
if (tag === 'TEMPLATE' && node.content instanceof DocumentFragment) { if (
tag === 'TEMPLATE' &&
node.content instanceof DocumentFragment
) {
return node.content return node.content
} }
return tag === 'SCRIPT' return tag === 'SCRIPT'
@ -111,14 +116,15 @@ function nodeToFragment (node) {
* - DocumentFragment object * - DocumentFragment object
* - Node object of type Template * - Node object of type Template
* - id selector: '#some-template-id' * - id selector: '#some-template-id'
* - template string: '<div><span>my template</span></div>' * - template string: '<div><span>{{msg}}</span></div>'
* @return {DocumentFragment|undefined} * @return {DocumentFragment|undefined}
*/ */
exports.parse = function (template) { exports.parse = function (template) {
var node, frag var node, frag
// if the template is already a document fragment -- do nothing // if the template is already a document fragment,
// do nothing
if (template instanceof DocumentFragment) { if (template instanceof DocumentFragment) {
return template return template
} }

View File

@ -1,9 +1,9 @@
var config = require('../config') var config = require('../config')
/** /**
* Enable debug utilities. The enableDebug() function and all * Enable debug utilities. The enableDebug() function and
* _.log() & _.warn() calls will be dropped in the minified * all _.log() & _.warn() calls will be dropped in the
* production build. * minified production build.
*/ */
enableDebug() enableDebug()

View File

@ -1,14 +1,15 @@
/** /**
* Are we in a browser or in Node? * Are we in a browser or in Node?
* Calling toString on window has inconsistent results in browsers * Calling toString on window has inconsistent results in
* so we do it on the document instead. * browsers so we do it on the document instead.
* *
* @type {Boolean} * @type {Boolean}
*/ */
var toString = Object.prototype.toString
var inBrowser = exports.inBrowser = var inBrowser = exports.inBrowser =
typeof window !== 'undefined' && typeof window !== 'undefined' &&
Object.prototype.toString.call(window) !== '[object Object]' toString.call(window) !== '[object Object]'
/** /**
* Defer a task to the start of the next event loop * Defer a task to the start of the next event loop

View File

@ -19,7 +19,6 @@ exports.bind = function (fn, ctx) {
*/ */
var slice = [].slice var slice = [].slice
exports.toArray = function (list, i) { exports.toArray = function (list, i) {
return slice.call(list, i || 0) return slice.call(list, i || 0)
} }
@ -38,7 +37,8 @@ exports.extend = function (to, from) {
} }
/** /**
* Mixin including non-enumerables, and copy property descriptors. * Mixin including non-enumerables, and copy property
* descriptors.
* *
* @param {Object} to * @param {Object} to
* @param {Object} from * @param {Object} from
@ -46,8 +46,8 @@ exports.extend = function (to, from) {
exports.deepMixin = function (to, from) { exports.deepMixin = function (to, from) {
Object.getOwnPropertyNames(from).forEach(function (key) { Object.getOwnPropertyNames(from).forEach(function (key) {
var descriptor = Object.getOwnPropertyDescriptor(from, key) var desc =Object.getOwnPropertyDescriptor(from, key)
Object.defineProperty(to, key, descriptor) Object.defineProperty(to, key, desc)
}) })
} }
@ -81,8 +81,9 @@ exports.proxy = function (to, from, key) {
* @return {Boolean} * @return {Boolean}
*/ */
var toString = Object.prototype.toString
exports.isObject = function (obj) { exports.isObject = function (obj) {
return Object.prototype.toString.call(obj) === '[object Object]' return toString.call(obj) === '[object Object]'
} }
/** /**

View File

@ -1,4 +1,4 @@
// alias debug as _ so we can drop _.warn during uglification // alias debug as _ so we can drop _.warn during uglify
var _ = require('./debug') var _ = require('./debug')
var extend = require('./lang').extend var extend = require('./lang').extend
@ -35,8 +35,8 @@ strats.paramAttributes = function (parentVal, childVal) {
* Assets * Assets
* *
* When a vm is present (instance creation), we need to do a * When a vm is present (instance creation), we need to do a
* 3-way merge for assets: constructor assets, instance assets, * 3-way merge for assets: constructor assets, instance
* and instance scope assets. * assets, and instance scope assets.
*/ */
strats.directives = strats.directives =
@ -76,7 +76,8 @@ strats.events = function (parentVal, childVal) {
/** /**
* Other object hashes. * Other object hashes.
* These are instance-specific and do not inehrit from nested parents. * These are instance-specific and do not inehrit from
* nested parents.
*/ */
strats.methods = strats.methods =
@ -124,10 +125,14 @@ exports.mergeOptions = function (parent, child, vm) {
} }
} }
function merge (key) { function merge (key) {
if (!vm && (key === 'el' || key === 'data' || key === 'parent')) { if (
!vm &&
(key === 'el' || key === 'data' || key === 'parent')
) {
_.warn( _.warn(
'The "' + key + '" option can only be used as an instantiation ' + 'The "' + key + '" option can only be used as an' +
'option and will be ignored in Vue.extend().' 'instantiation option and will be ignored in' +
'Vue.extend().'
) )
return return
} }

View File

@ -6,7 +6,8 @@ var extend = require('./util').extend
* API conventions: * API conventions:
* - public API methods/properties are prefiexed with `$` * - public API methods/properties are prefiexed with `$`
* - internal methods/properties are prefixed with `_` * - internal methods/properties are prefixed with `_`
* - non-prefixed properties are assumed to be proxied user data. * - non-prefixed properties are assumed to be proxied user
* data.
* *
* @constructor * @constructor
* @param {Object} [options] * @param {Object} [options]
@ -38,7 +39,8 @@ Object.defineProperty(p, '$root', {
}) })
/** /**
* $data has a setter which does a bunch of teardown/setup work * $data has a setter which does a bunch of
* teardown/setup work
*/ */
Object.defineProperty(p, '$data', { Object.defineProperty(p, '$data', {