mirror of https://github.com/vuejs/vue.git
comform source code width
This commit is contained in:
parent
d4accea3c6
commit
779ec3417f
|
|
@ -18,8 +18,8 @@ exports.$get = function (exp) {
|
|||
|
||||
/**
|
||||
* Set the value from an expression on this vm.
|
||||
* The expression must be a valid left-hand expression
|
||||
* in an assignment.
|
||||
* The expression must be a valid left-hand
|
||||
* expression in an assignment.
|
||||
*
|
||||
* @param {String} exp
|
||||
* @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 {*} 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
|
||||
*/
|
||||
|
|
@ -54,8 +56,9 @@ exports.$delete = function (key) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Watch an expression, trigger callback when its value changes.
|
||||
* Returns the created watcher's id so it can be teardown later.
|
||||
* Watch an expression, trigger callback when its
|
||||
* value changes. Returns the created watcher's
|
||||
* id so it can be teardown later.
|
||||
*
|
||||
* @param {String} exp
|
||||
* @param {Function} cb
|
||||
|
|
@ -86,6 +89,7 @@ exports.$unwatch = function (id) {
|
|||
* Interpolate a piece of template string.
|
||||
*
|
||||
* @param {String} string
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
exports.$interpolate = function (string) {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,10 @@
|
|||
? 'applyEmit'
|
||||
: method
|
||||
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
|
||||
for (var i = 0, l = children.length; i < l; i++) {
|
||||
var child = children[i]
|
||||
child._emitter.applyEmit.apply(child._emitter, arguments)
|
||||
child.$broadcast.apply(child, arguments)
|
||||
child._emitter.applyEmit.apply(
|
||||
child._emitter,
|
||||
arguments
|
||||
)
|
||||
child.$broadcast.apply(
|
||||
child,
|
||||
arguments
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -35,9 +44,15 @@ exports.$broadcast = function () {
|
|||
*/
|
||||
|
||||
exports.$dispatch = function () {
|
||||
this._emitter.applyEmit.apply(this._emitter, arguments)
|
||||
this._emitter.applyEmit.apply(
|
||||
this._emitter,
|
||||
arguments
|
||||
)
|
||||
var parent = this.$parent
|
||||
if (parent) {
|
||||
parent.$dispatch.apply(parent, arguments)
|
||||
parent.$dispatch.apply(
|
||||
parent,
|
||||
arguments
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -8,9 +8,9 @@ var assetTypes = [
|
|||
]
|
||||
|
||||
/**
|
||||
* Vue and every constructor that extends Vue has an associated
|
||||
* options object, which can be accessed during compilation steps
|
||||
* as `this.constructor.options`.
|
||||
* Vue and every constructor that extends Vue has an
|
||||
* associated options object, which can be accessed during
|
||||
* compilation steps as `this.constructor.options`.
|
||||
*/
|
||||
|
||||
exports.options = {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
/**
|
||||
* Set instance target element and kick off the compilation process.
|
||||
* The passed in `el` can be a selector string, an existing Element,
|
||||
* or a DocumentFragment (for block instances).
|
||||
* Set instance target element and kick off the compilation
|
||||
* process. The passed in `el` can be a selector string, an
|
||||
* existing Element, or a DocumentFragment (for block
|
||||
* instances).
|
||||
*
|
||||
* @param {Element|DocumentFragment|string} el
|
||||
* @public
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* A binding is an observable that can have multiple directives
|
||||
* subscribing to it. It can also have multiple other bindings
|
||||
* as children to form a trie-like structure.
|
||||
* A binding is an observable that can have multiple
|
||||
* directives subscribing to it. It can also have multiple
|
||||
* other bindings as children to form a trie-like structure.
|
||||
*
|
||||
* All binding properties are prefixed with `_` so that they
|
||||
* don't conflict with children keys.
|
||||
|
|
|
|||
14
src/cache.js
14
src/cache.js
|
|
@ -1,8 +1,9 @@
|
|||
/**
|
||||
* A doubly linked list-based Least Recently Used (LRU) cache.
|
||||
* Will keep most recently used items while discarding least
|
||||
* recently used items when its limit is reached. This is a
|
||||
* bare-bone version of Rasmus Andersson's js-lru:
|
||||
* A doubly linked list-based Least Recently Used (LRU)
|
||||
* cache. Will keep most recently used items while
|
||||
* discarding least recently used items when its limit is
|
||||
* reached. This is a bare-bone version of
|
||||
* Rasmus Andersson's 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.
|
||||
* Returns the removed entry or undefined if the cache was empty.
|
||||
* Purge the least recently used (oldest) entry from the
|
||||
* cache. Returns the removed entry or undefined if the
|
||||
* cache was empty.
|
||||
*/
|
||||
|
||||
p.shift = function () {
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ var _ = require('./util')
|
|||
var Watcher = require('./watcher')
|
||||
|
||||
/**
|
||||
* A directive links a DOM element with a piece of data, which can
|
||||
* be either simple paths or computed properties. It subscribes to
|
||||
* a list of dependencies (Bindings) and refreshes the list during
|
||||
* its getter evaluation.
|
||||
* A directive links a DOM element with a piece of data,
|
||||
* which is the result of evaluating an expression.
|
||||
* It registers a watcher with the expression and calls
|
||||
* the DOM update function when a change is triggered.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Node} el
|
||||
|
|
@ -113,7 +113,8 @@ p._teardown = function () {
|
|||
|
||||
/**
|
||||
* 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 {Boolean} lock - prevent wrtie triggering update.
|
||||
|
|
|
|||
|
|
@ -5,18 +5,13 @@ var Observer = require('../observe/observer')
|
|||
/**
|
||||
* Setup the binding tree.
|
||||
*
|
||||
* Bindings form a tree-like structure that maps the Object structure
|
||||
* of observed data. However, only paths present in the templates are
|
||||
* created in the binding tree. When a change event from the data
|
||||
* observer arrives on the instance, we traverse the binding tree
|
||||
* along the changed path, triggering binding updates along the way.
|
||||
* When we reach the path endpoint, if it has any children, we also
|
||||
* trigger updates on the entire sub-tree.
|
||||
*
|
||||
* 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.
|
||||
* Bindings form a tree-like structure that maps the Object
|
||||
* structure of observed data. However, only paths present
|
||||
* in the templates are created in the binding tree. When a
|
||||
* change event from the data observer arrives on the
|
||||
* instance, we traverse the binding tree along the changed
|
||||
* path to find the corresponding binding, and trigger
|
||||
* change for all its subscribers.
|
||||
*/
|
||||
|
||||
exports._initBindings = function () {
|
||||
|
|
@ -90,11 +85,12 @@ exports._updateBindingAt = function (path) {
|
|||
}
|
||||
|
||||
/**
|
||||
* For newly added properties, since its binding has not been
|
||||
* created yet, directives will not have it as a dependency yet.
|
||||
* However, they will have its parent as a dependency. Therefore
|
||||
* here we remove the last segment from the path and notify the
|
||||
* added property's parent instead.
|
||||
* For newly added properties, since its binding has not
|
||||
* been created yet, directives will not have it as a
|
||||
* dependency yet. However, they will have its parent as a
|
||||
* dependency. Therefore here we remove the last segment
|
||||
* from the path and notify the added property's parent
|
||||
* instead.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -18,10 +18,10 @@ exports._initElement = function (el) {
|
|||
_.warn('Cannot find element: ' + selector)
|
||||
}
|
||||
}
|
||||
// If the passed in `el` is a DocumentFragment, the instance is
|
||||
// considered a "block instance" which manages not a single element,
|
||||
// but multiple elements. A block instance's `$el` is an Array of
|
||||
// the elements it manages.
|
||||
// If the passed in `el` is a DocumentFragment, the
|
||||
// instance is considered a "block instance" which manages
|
||||
// not a single element, but multiple elements. A block
|
||||
// instance's `$el` is an Array of the elements it manages.
|
||||
if (el instanceof window.DocumentFragment) {
|
||||
this._isBlock = true
|
||||
this.$el = _.toArray(el.childNodes)
|
||||
|
|
@ -34,7 +34,7 @@ exports._initElement = function (el) {
|
|||
|
||||
/**
|
||||
* 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 () {
|
||||
|
|
@ -46,7 +46,7 @@ exports._initTemplate = function () {
|
|||
if (!frag) {
|
||||
_.warn('Invalid template option: ' + template)
|
||||
} else {
|
||||
// collect raw content. this wipes out the container el.
|
||||
// collect raw content. this wipes out $el.
|
||||
this._collectRawContent()
|
||||
frag = frag.cloneNode(true)
|
||||
if (options.replace) {
|
||||
|
|
@ -93,10 +93,10 @@ exports._collectRawContent = function () {
|
|||
}
|
||||
|
||||
/**
|
||||
* Resolve <content> insertion points per W3C Web Components
|
||||
* working draft:
|
||||
* Resolve <content> insertion points mimicking the behavior
|
||||
* 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 () {
|
||||
|
|
@ -112,7 +112,9 @@ exports._initContent = function () {
|
|||
if (raw) {
|
||||
select = outlet.getAttribute('select')
|
||||
if (select) { // select content
|
||||
outlet.content = _.toArray(raw.querySelectorAll(select))
|
||||
outlet.content = _.toArray(
|
||||
raw.querySelectorAll(select)
|
||||
)
|
||||
} else { // default content
|
||||
main = outlet
|
||||
}
|
||||
|
|
@ -142,7 +144,6 @@ exports._initContent = function () {
|
|||
*/
|
||||
|
||||
var concat = [].concat
|
||||
|
||||
function getOutlets (el) {
|
||||
return _.isArray(el)
|
||||
? 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 {Array} contents
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ exports._initEvents = function () {
|
|||
for (e in events) {
|
||||
handlers = events[e]
|
||||
for (i = 0, j = handlers.length; i < j; i++) {
|
||||
var handler = (methods && typeof handlers[i] === 'string')
|
||||
? methods[handlers[i]]
|
||||
var handler = typeof handlers[i] === 'string'
|
||||
? methods && methods[handlers[i]]
|
||||
: handlers[i]
|
||||
this.$on(e, handler)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,14 @@ var Emitter = require('../emitter')
|
|||
var mergeOptions = require('../util').mergeOptions
|
||||
|
||||
/**
|
||||
* The main init sequence. This is called for every instance,
|
||||
* including ones that are created from extended constructors.
|
||||
* The main init sequence. This is called for every
|
||||
* instance, including ones that are created from extended
|
||||
* constructors.
|
||||
*
|
||||
* @param {Object} options - this options object should be the
|
||||
* result of merging class options
|
||||
* and the options passed in to the
|
||||
* constructor.
|
||||
* @param {Object} options - this options object should be
|
||||
* the result of merging class
|
||||
* options and the options passed
|
||||
* in to the constructor.
|
||||
*/
|
||||
|
||||
exports._init = function (options) {
|
||||
|
|
@ -39,8 +40,8 @@ exports._init = function (options) {
|
|||
this
|
||||
)
|
||||
|
||||
// the `created` hook is called after basic properties have
|
||||
// been set up & before data observation happens.
|
||||
// the `created` hook is called after basic properties
|
||||
// have been set up & before data observation happens.
|
||||
this._callHook('created')
|
||||
|
||||
// create scope.
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ var scopeEvents = ['set', 'mutate', 'add', 'delete']
|
|||
* Setup instance scope.
|
||||
* The scope is reponsible for prototypal inheritance of
|
||||
* 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().
|
||||
*/
|
||||
|
|
@ -64,20 +65,22 @@ exports._teardownScope = function () {
|
|||
/**
|
||||
* Setup the instances data object.
|
||||
*
|
||||
* Properties are copied into the scope object to take advantage of
|
||||
* prototypal inheritance.
|
||||
* Properties are copied into the scope object to take
|
||||
* advantage of prototypal inheritance.
|
||||
*
|
||||
* If the `syncData` option is true, Vue will maintain property
|
||||
* syncing between the scope and the original data object, so that
|
||||
* any changes to the scope are synced back to the passed in object.
|
||||
* This is useful internally when e.g. creating v-repeat instances
|
||||
* with no alias.
|
||||
* If the `syncData` option is true, Vue will maintain
|
||||
* property syncing between the scope and the original data
|
||||
* object, so that any changes to the scope are synced back
|
||||
* to the passed in object. This is useful internally when
|
||||
* e.g. creating v-repeat instances with no alias.
|
||||
*
|
||||
* If swapping data object with the `$data` accessor, teardown
|
||||
* previous sync listeners and delete keys not present in new data.
|
||||
* If swapping data object with the `$data` accessor,
|
||||
* teardown previous sync listeners and delete keys not
|
||||
* present in new 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) {
|
||||
|
|
@ -120,13 +123,13 @@ exports._initData = function (data, init) {
|
|||
* Proxy the scope properties on the instance itself,
|
||||
* so that vm.a === vm.$scope.a.
|
||||
*
|
||||
* Note this only proxies *local* scope properties. We want to
|
||||
* prevent child instances accidentally modifying properties
|
||||
* with the same name up in the scope chain because scope
|
||||
* perperties are all getter/setters.
|
||||
* Note this only proxies *local* scope properties. We want
|
||||
* to prevent child instances accidentally modifying
|
||||
* properties with the same name up in the scope chain
|
||||
* because scope perperties are all getter/setters.
|
||||
*
|
||||
* To access parent properties through prototypal fall through,
|
||||
* access it on the instance's $scope.
|
||||
* To access parent properties through prototypal fall
|
||||
* through, access it on the instance's $scope.
|
||||
*
|
||||
* This should only be called once during _init().
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ var OBJECT = 1
|
|||
* @param {Array|Object} value
|
||||
* @param {Number} type
|
||||
* @param {Object} [options]
|
||||
* - doNotAlterProto: if true, do not alter object's __proto__
|
||||
* - callbackContext: `this` context for callbacks
|
||||
* - doNotAlterProto
|
||||
* - callbackContext
|
||||
*/
|
||||
|
||||
function Observer (value, type, options) {
|
||||
|
|
@ -90,15 +90,19 @@ Observer.create = function (value, options) {
|
|||
return value.$observer
|
||||
} if (_.isArray(value)) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Walk through each property, converting them and adding them as child.
|
||||
* This method should only be called when value type is Object.
|
||||
* Properties prefixed with `$` or `_` and accessor properties are ignored.
|
||||
* Walk through each property, converting them and adding
|
||||
* them as child. This method should only be called when
|
||||
* value type is Object. Properties prefixed with `$` or `_`
|
||||
* and accessor properties are ignored.
|
||||
*
|
||||
* @param {Object} obj
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -58,8 +58,8 @@ function pushFilter () {
|
|||
}
|
||||
|
||||
/**
|
||||
* Parse a directive string into an Array of AST-like objects
|
||||
* representing directives.
|
||||
* Parse a directive string into an Array of AST-like
|
||||
* objects representing directives.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
|
|
@ -86,7 +86,8 @@ exports.parse = function (s) {
|
|||
// reset parser state
|
||||
str = s
|
||||
inSingle = inDouble = false
|
||||
curly = square = paren = begin = argIndex = lastFilterIndex = 0
|
||||
curly = square = paren = begin = argIndex = 0
|
||||
lastFilterIndex = 0
|
||||
dirs = []
|
||||
dir = {}
|
||||
arg = null
|
||||
|
|
@ -99,13 +100,20 @@ exports.parse = function (s) {
|
|||
} else if (inDouble) {
|
||||
// check double quote
|
||||
if (c === '"') inDouble = !inDouble
|
||||
} else if (c === ',' && !paren && !curly && !square) {
|
||||
} else if (
|
||||
c === ',' &&
|
||||
!paren && !curly && !square
|
||||
) {
|
||||
// reached the end of a directive
|
||||
pushDir()
|
||||
// reset & skip the comma
|
||||
dir = {}
|
||||
begin = argIndex = lastFilterIndex = i + 1
|
||||
} else if (c === ':' && !dir.expression && !dir.arg) {
|
||||
} else if (
|
||||
c === ':' &&
|
||||
!dir.expression &&
|
||||
!dir.arg
|
||||
) {
|
||||
// argument
|
||||
arg = str.slice(begin, i).trim()
|
||||
// test for valid argument here
|
||||
|
|
@ -119,7 +127,11 @@ exports.parse = function (s) {
|
|||
? arg.slice(1, -1)
|
||||
: 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) {
|
||||
// first filter, end of expression
|
||||
lastFilterIndex = i + 1
|
||||
|
|
|
|||
|
|
@ -3,26 +3,36 @@ var Path = require('./path')
|
|||
var Cache = require('../cache')
|
||||
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 newlineRE = /\n/g
|
||||
var saveRE = /[\{,]\s*[\w\$_]+\s*:|'[^']*'|"[^"]*"/g
|
||||
var restoreRE = /"(\d+)"/g
|
||||
var pathTestRE = /^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\])*$/
|
||||
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)')
|
||||
// note the following regex is only used on valid paths
|
||||
// so no need to exclude number for first char
|
||||
var rootPathRE = /^[\w$]+/
|
||||
var rootPathRE = /^[\w$]+/ // this is only used on valid
|
||||
// paths so no need to exclude
|
||||
// number for first char
|
||||
|
||||
/**
|
||||
* Save / Rewrite / Restore
|
||||
*
|
||||
* When rewriting paths found in an expression, it is possible
|
||||
* for the same letter sequences to be found in strings and Object
|
||||
* literal property keys. Therefore we remove and store these
|
||||
* parts in a temporary array, and restore them after the path
|
||||
* rewrite.
|
||||
* When rewriting paths found in an expression, it is
|
||||
* possible for the same letter sequences to be found in
|
||||
* strings and Object literal property keys. Therefore we
|
||||
* remove and store these parts in a temporary array, and
|
||||
* restore them after the path rewrite.
|
||||
*/
|
||||
|
||||
var saved = []
|
||||
|
|
@ -84,8 +94,8 @@ function restore (str, i) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Rewrite an expression, prefixing all path accessors with `scope.`
|
||||
* and generate getter/setter functions.
|
||||
* Rewrite an expression, prefixing all path accessors with
|
||||
* `scope.` and generate getter/setter functions.
|
||||
*
|
||||
* @param {String} exp
|
||||
* @param {Boolean} needSet
|
||||
|
|
@ -151,8 +161,8 @@ function compilePathFns (exp) {
|
|||
/**
|
||||
* Build a getter function. Requires eval.
|
||||
*
|
||||
* We isolate the try/catch so it doesn't affect the optimization
|
||||
* of the parse function when it is not called.
|
||||
* We isolate the try/catch so it doesn't affect the
|
||||
* optimization of the parse function when it is not called.
|
||||
*
|
||||
* @param {String} body
|
||||
* @return {Function|undefined}
|
||||
|
|
@ -162,7 +172,10 @@ function makeGetter (body) {
|
|||
try {
|
||||
return new Function('scope', 'return ' + body + ';')
|
||||
} 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) {
|
||||
try {
|
||||
return new Function('scope', 'value', body + ' = value;')
|
||||
return new Function(
|
||||
'scope',
|
||||
'value',
|
||||
body + ' = value;'
|
||||
)
|
||||
} catch (e) {
|
||||
_.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 {Boolean} needSet
|
||||
|
|
@ -218,9 +235,9 @@ exports.parse = function (exp, needSet) {
|
|||
}
|
||||
return hit
|
||||
}
|
||||
// we do a simple path check to optimize for that scenario.
|
||||
// the check fails valid paths with unusal whitespaces, but
|
||||
// that's too rare and we don't care.
|
||||
// we do a simple path check to optimize for them.
|
||||
// the check fails valid paths with unusal whitespaces,
|
||||
// but that's too rare and we don't care.
|
||||
var res = pathTestRE.test(exp)
|
||||
? compilePathFns(exp)
|
||||
: compileExpFns(exp, needSet)
|
||||
|
|
|
|||
|
|
@ -140,7 +140,8 @@ function getPathCharType (char) {
|
|||
function parsePath (path) {
|
||||
var keys = []
|
||||
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 = {
|
||||
push: function() {
|
||||
|
|
@ -188,7 +189,9 @@ function parsePath (path) {
|
|||
|
||||
mode = transition[0]
|
||||
action = actions[transition[1]] || noop
|
||||
newChar = transition[2] === undefined ? c : transition[2]
|
||||
newChar = transition[2] === undefined
|
||||
? c
|
||||
: transition[2]
|
||||
action()
|
||||
|
||||
if (mode === 'afterPath') {
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ var TAG_RE = /<([\w:]+)/
|
|||
|
||||
/**
|
||||
* Convert a string template to a DocumentFragment.
|
||||
* Determines correct wrapping by tag types. Wrapping strategy
|
||||
* originally from jQuery, scooped from component/domify.
|
||||
* Determines correct wrapping by tag types. Wrapping
|
||||
* strategy found in jQuery & component/domify.
|
||||
*
|
||||
* @param {String} templateString
|
||||
* @return {DocumentFragment}
|
||||
|
|
@ -56,7 +56,9 @@ function stringToFragment (templateString) {
|
|||
|
||||
if (!tagMatch) {
|
||||
// text only, return a single text node.
|
||||
frag.appendChild(document.createTextNode(templateString))
|
||||
frag.appendChild(
|
||||
document.createTextNode(templateString)
|
||||
)
|
||||
} else {
|
||||
|
||||
var tag = tagMatch[1]
|
||||
|
|
@ -93,7 +95,10 @@ function nodeToFragment (node) {
|
|||
var tag = node.tagName
|
||||
// if its a template tag and the browser supports it,
|
||||
// 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 tag === 'SCRIPT'
|
||||
|
|
@ -111,14 +116,15 @@ function nodeToFragment (node) {
|
|||
* - DocumentFragment object
|
||||
* - Node object of type Template
|
||||
* - id selector: '#some-template-id'
|
||||
* - template string: '<div><span>my template</span></div>'
|
||||
* - template string: '<div><span>{{msg}}</span></div>'
|
||||
* @return {DocumentFragment|undefined}
|
||||
*/
|
||||
|
||||
exports.parse = function (template) {
|
||||
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) {
|
||||
return template
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
var config = require('../config')
|
||||
|
||||
/**
|
||||
* Enable debug utilities. The enableDebug() function and all
|
||||
* _.log() & _.warn() calls will be dropped in the minified
|
||||
* production build.
|
||||
* Enable debug utilities. The enableDebug() function and
|
||||
* all _.log() & _.warn() calls will be dropped in the
|
||||
* minified production build.
|
||||
*/
|
||||
|
||||
enableDebug()
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
/**
|
||||
* Are we in a browser or in Node?
|
||||
* Calling toString on window has inconsistent results in browsers
|
||||
* so we do it on the document instead.
|
||||
* Calling toString on window has inconsistent results in
|
||||
* browsers so we do it on the document instead.
|
||||
*
|
||||
* @type {Boolean}
|
||||
*/
|
||||
|
||||
var toString = Object.prototype.toString
|
||||
var inBrowser = exports.inBrowser =
|
||||
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
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ exports.bind = function (fn, ctx) {
|
|||
*/
|
||||
|
||||
var slice = [].slice
|
||||
|
||||
exports.toArray = function (list, i) {
|
||||
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} from
|
||||
|
|
@ -46,8 +46,8 @@ exports.extend = function (to, from) {
|
|||
|
||||
exports.deepMixin = function (to, from) {
|
||||
Object.getOwnPropertyNames(from).forEach(function (key) {
|
||||
var descriptor = Object.getOwnPropertyDescriptor(from, key)
|
||||
Object.defineProperty(to, key, descriptor)
|
||||
var desc =Object.getOwnPropertyDescriptor(from, key)
|
||||
Object.defineProperty(to, key, desc)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -81,8 +81,9 @@ exports.proxy = function (to, from, key) {
|
|||
* @return {Boolean}
|
||||
*/
|
||||
|
||||
var toString = Object.prototype.toString
|
||||
exports.isObject = function (obj) {
|
||||
return Object.prototype.toString.call(obj) === '[object Object]'
|
||||
return toString.call(obj) === '[object Object]'
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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 extend = require('./lang').extend
|
||||
|
||||
|
|
@ -35,8 +35,8 @@ strats.paramAttributes = function (parentVal, childVal) {
|
|||
* Assets
|
||||
*
|
||||
* When a vm is present (instance creation), we need to do a
|
||||
* 3-way merge for assets: constructor assets, instance assets,
|
||||
* and instance scope assets.
|
||||
* 3-way merge for assets: constructor assets, instance
|
||||
* assets, and instance scope assets.
|
||||
*/
|
||||
|
||||
strats.directives =
|
||||
|
|
@ -76,7 +76,8 @@ strats.events = function (parentVal, childVal) {
|
|||
|
||||
/**
|
||||
* 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 =
|
||||
|
|
@ -124,10 +125,14 @@ exports.mergeOptions = function (parent, child, vm) {
|
|||
}
|
||||
}
|
||||
function merge (key) {
|
||||
if (!vm && (key === 'el' || key === 'data' || key === 'parent')) {
|
||||
if (
|
||||
!vm &&
|
||||
(key === 'el' || key === 'data' || key === 'parent')
|
||||
) {
|
||||
_.warn(
|
||||
'The "' + key + '" option can only be used as an instantiation ' +
|
||||
'option and will be ignored in Vue.extend().'
|
||||
'The "' + key + '" option can only be used as an' +
|
||||
'instantiation option and will be ignored in' +
|
||||
'Vue.extend().'
|
||||
)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ var extend = require('./util').extend
|
|||
* API conventions:
|
||||
* - public API methods/properties are prefiexed 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
|
||||
* @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', {
|
||||
|
|
|
|||
Loading…
Reference in New Issue