Comparing version 0.12.7 to 0.12.8
{ | ||
"name": "vue", | ||
"version": "0.12.7", | ||
"version": "0.12.8", | ||
"author": "Evan You <yyx990803@gmail.com>", | ||
@@ -21,4 +21,12 @@ "license": "MIT", | ||
"test": "grunt ci", | ||
"dev": "webpack --watch --config build/webpack-dev-config.js & webpack --watch --config build/webpack-test-config.js" | ||
"dev": "webpack --watch --config build/webpack.dev.config.js & webpack --watch --config build/webpack.test.config.js" | ||
}, | ||
"dependencies": { | ||
"envify": "^3.4.0" | ||
}, | ||
"browserify": { | ||
"transform": [ | ||
"envify" | ||
] | ||
}, | ||
"devDependencies": { | ||
@@ -25,0 +33,0 @@ "casperjs": "^1.1.0-beta3", |
var _ = require('../util') | ||
/** | ||
* Create a child instance that prototypally inehrits | ||
* Create a child instance that prototypally inherits | ||
* data on parent. To achieve that we create an intermediate | ||
@@ -6,0 +6,0 @@ * constructor with its prototype pointing to parent. |
@@ -9,4 +9,4 @@ var _ = require('../util') | ||
exports.util = _ | ||
exports.config = config | ||
exports.nextTick = _.nextTick | ||
exports.config = require('../config') | ||
exports.compiler = require('../compiler') | ||
@@ -32,3 +32,3 @@ | ||
/** | ||
* Class inehritance | ||
* Class inheritance | ||
* | ||
@@ -35,0 +35,0 @@ * @param {Object} extendOptions |
@@ -16,3 +16,5 @@ var _ = require('../util') | ||
if (this._isCompiled) { | ||
_.warn('$mount() should be called only once.') | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'$mount() should be called only once.' | ||
) | ||
return | ||
@@ -19,0 +21,0 @@ } |
@@ -74,3 +74,3 @@ var _ = require('./util') | ||
if (has[id] > config._maxUpdateCount) { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'You may have an infinite update loop for the ' + | ||
@@ -77,0 +77,0 @@ 'watcher with expression: "' + job.expression + '".' |
@@ -24,3 +24,3 @@ var _ = require('../util') | ||
var i = propOptions.length | ||
var options, name, value, path, prop, literal, single | ||
var options, name, attr, value, path, prop, literal, single | ||
while (i--) { | ||
@@ -34,8 +34,14 @@ options = propOptions[i] | ||
if (!identRE.test(path)) { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Invalid prop key: "' + name + '". Prop keys ' + | ||
'must be valid identifiers.' | ||
) | ||
continue | ||
} | ||
value = el.getAttribute(_.hyphenate(name)) | ||
attr = _.hyphenate(name) | ||
value = el.getAttribute(attr) | ||
if (value === null) { | ||
attr = 'data-' + attr | ||
value = el.getAttribute(attr) | ||
} | ||
// create a prop descriptor | ||
@@ -52,8 +58,5 @@ prop = { | ||
// again as a normal attribute binding | ||
el.removeAttribute(name) | ||
el.removeAttribute(attr) | ||
var tokens = textParser.parse(value) | ||
if (tokens) { | ||
if (el && el.nodeType === 1) { | ||
el.removeAttribute(name) | ||
} | ||
prop.dynamic = true | ||
@@ -74,3 +77,3 @@ prop.parentPath = textParser.tokensToExp(tokens) | ||
} else { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Cannot bind two-way prop with non-settable ' + | ||
@@ -81,5 +84,16 @@ 'parent path: ' + prop.parentPath | ||
} | ||
if ( | ||
process.env.NODE_ENV !== 'production' && | ||
options.twoWay && | ||
prop.mode !== propBindingModes.TWO_WAY | ||
) { | ||
_.warn( | ||
'Prop "' + name + '" expects a two-way binding type.' | ||
) | ||
} | ||
} | ||
} else if (options && options.required) { | ||
_.warn('Missing required prop: ' + name) | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Missing required prop: ' + name | ||
) | ||
} | ||
@@ -111,7 +125,3 @@ props.push(prop) | ||
// initialize absent prop | ||
vm._data[path] = options.type === Boolean | ||
? false | ||
: options.hasOwnProperty('default') | ||
? options.default | ||
: undefined | ||
_.initProp(vm, prop, getDefault(options)) | ||
} else if (prop.dynamic) { | ||
@@ -129,3 +139,3 @@ // dynamic prop | ||
} else { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Cannot bind dynamic prop on a root instance' + | ||
@@ -146,1 +156,32 @@ ' with no parent: ' + prop.name + '="' + | ||
} | ||
/** | ||
* Get the default value of a prop. | ||
* | ||
* @param {Object} options | ||
* @return {*} | ||
*/ | ||
function getDefault (options) { | ||
// absent boolean value | ||
if (options.type === Boolean) { | ||
return false | ||
} | ||
// no default, return undefined | ||
if (!options.hasOwnProperty('default')) { | ||
return | ||
} | ||
var def = options.default | ||
// warn against non-factory defaults for Object & Array | ||
if (_.isObject(def)) { | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Object/Array as default prop values will be shared ' + | ||
'across multiple instances. Use a factory function ' + | ||
'to return the default value instead.' | ||
) | ||
} | ||
// call factory function for non-Function types | ||
return typeof def === 'function' && options.type !== Function | ||
? def() | ||
: def | ||
} |
@@ -525,3 +525,5 @@ var _ = require('../util') | ||
dirDef = resolveAsset(options, 'directives', dirName) | ||
_.assertAsset(dirDef, 'directive', dirName) | ||
if (process.env.NODE_ENV !== 'production') { | ||
_.assertAsset(dirDef, 'directive', dirName) | ||
} | ||
if (dirDef) { | ||
@@ -598,2 +600,6 @@ dirs.push({ | ||
* | ||
* Special case: class interpolations are translated into | ||
* v-class instead v-attr, so that it can work with user | ||
* provided v-class bindings. | ||
* | ||
* @param {String} name | ||
@@ -607,4 +613,6 @@ * @param {String} value | ||
var tokens = textParser.parse(value) | ||
var isClass = name === 'class' | ||
if (tokens) { | ||
var def = options.directives.attr | ||
var dirName = isClass ? 'class' : 'attr' | ||
var def = options.directives[dirName] | ||
var i = tokens.length | ||
@@ -625,5 +633,10 @@ var allOneTime = true | ||
: function (vm, el) { | ||
var value = textParser.tokensToExp(tokens, vm) | ||
var desc = dirParser.parse(name + ':' + value)[0] | ||
vm._bindDir('attr', el, desc, def) | ||
var exp = textParser.tokensToExp(tokens, vm) | ||
var desc = isClass | ||
? dirParser.parse(exp)[0] | ||
: dirParser.parse(name + ':' + exp)[0] | ||
if (isClass) { | ||
desc._rawClass = value | ||
} | ||
vm._bindDir(dirName, el, desc, def) | ||
} | ||
@@ -630,0 +643,0 @@ } |
@@ -62,5 +62,3 @@ var _ = require('../util') | ||
var frag = templateParser.parse(template, true) | ||
if (!frag) { | ||
_.warn('Invalid template option: ' + template) | ||
} else { | ||
if (frag) { | ||
var replacer = frag.firstChild | ||
@@ -71,3 +69,3 @@ var tag = replacer.tagName && replacer.tagName.toLowerCase() | ||
if (el === document.body) { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'You are mounting an instance with a template to ' + | ||
@@ -101,2 +99,6 @@ '<body>. This will replace <body> entirely. You ' + | ||
} | ||
} else { | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Invalid template option: ' + template | ||
) | ||
} | ||
@@ -103,0 +105,0 @@ } |
@@ -55,3 +55,6 @@ var _ = require('./util') | ||
p._bind = function (def) { | ||
if (this.name !== 'cloak' && this.el && this.el.removeAttribute) { | ||
if ( | ||
(this.name !== 'cloak' || this.vm._isCompiled) && | ||
this.el && this.el.removeAttribute | ||
) { | ||
this.el.removeAttribute(config.prefix + this.name) | ||
@@ -58,0 +61,0 @@ } |
@@ -47,4 +47,7 @@ // xlink | ||
} | ||
if (attr in this.el) { | ||
this.el[attr] = value | ||
} | ||
} | ||
} |
@@ -7,23 +7,27 @@ var _ = require('../util') | ||
bind: function () { | ||
// interpolations like class="{{abc}}" are converted | ||
// to v-class, and we need to remove the raw, | ||
// uninterpolated className at binding time. | ||
var raw = this._descriptor._rawClass | ||
if (raw) { | ||
this.prevKeys = raw.trim().split(/\s+/) | ||
} | ||
}, | ||
update: function (value) { | ||
if (this.arg) { | ||
// single toggle | ||
var method = value ? addClass : removeClass | ||
method(this.el, this.arg) | ||
if (value) { | ||
addClass(this.el, this.arg) | ||
} else { | ||
removeClass(this.el, this.arg) | ||
} | ||
} else { | ||
this.cleanup() | ||
if (value && typeof value === 'string') { | ||
// raw class text | ||
addClass(this.el, value) | ||
this.lastVal = value | ||
this.handleObject(stringToObject(value)) | ||
} else if (_.isPlainObject(value)) { | ||
// object toggle | ||
for (var key in value) { | ||
if (value[key]) { | ||
addClass(this.el, key) | ||
} else { | ||
removeClass(this.el, key) | ||
} | ||
} | ||
this.prevKeys = Object.keys(value) | ||
this.handleObject(value) | ||
} else { | ||
this.cleanup() | ||
} | ||
@@ -33,11 +37,22 @@ } | ||
handleObject: function (value) { | ||
this.cleanup(value) | ||
var keys = this.prevKeys = Object.keys(value) | ||
for (var i = 0, l = keys.length; i < l; i++) { | ||
var key = keys[i] | ||
if (value[key]) { | ||
addClass(this.el, key) | ||
} else { | ||
removeClass(this.el, key) | ||
} | ||
} | ||
}, | ||
cleanup: function (value) { | ||
if (this.lastVal) { | ||
removeClass(this.el, this.lastVal) | ||
} | ||
if (this.prevKeys) { | ||
var i = this.prevKeys.length | ||
while (i--) { | ||
if (!value || !value[this.prevKeys[i]]) { | ||
removeClass(this.el, this.prevKeys[i]) | ||
var key = this.prevKeys[i] | ||
if (!value || !value.hasOwnProperty(key)) { | ||
removeClass(this.el, key) | ||
} | ||
@@ -48,1 +63,11 @@ } | ||
} | ||
function stringToObject (value) { | ||
var res = {} | ||
var keys = value.trim().split(/\s+/) | ||
var i = keys.length | ||
while (i--) { | ||
res[keys[i]] = true | ||
} | ||
return res | ||
} |
@@ -53,3 +53,3 @@ var _ = require('../util') | ||
} else { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Do not create a component that only contains ' + | ||
@@ -56,0 +56,0 @@ 'a single other component - they will be mounted to ' + |
@@ -28,7 +28,7 @@ var _ = require('../util') | ||
} else { | ||
this.invalid = true | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'v-if="' + this.expression + '" cannot be ' + | ||
'used on an instance root element.' | ||
) | ||
this.invalid = true | ||
} | ||
@@ -35,0 +35,0 @@ }, |
@@ -32,3 +32,3 @@ var _ = require('../../util') | ||
if (this.hasRead && !this.hasWrite) { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'It seems you are using a read-only filter with ' + | ||
@@ -49,3 +49,5 @@ 'v-model. You might want to use a two-way filter ' + | ||
} else { | ||
_.warn('v-model does not support element type: ' + tag) | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'v-model does not support element type: ' + tag | ||
) | ||
return | ||
@@ -52,0 +54,0 @@ } |
@@ -85,3 +85,5 @@ var _ = require('../../util') | ||
} else { | ||
_.warn('Invalid options value for v-model: ' + value) | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Invalid options value for v-model: ' + value | ||
) | ||
} | ||
@@ -88,0 +90,0 @@ } |
@@ -24,5 +24,6 @@ var _ = require('../util') | ||
if (typeof handler !== 'function') { | ||
_.warn( | ||
'Directive "v-on:' + this.expression + '" ' + | ||
'expects a function value.' | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Directive v-on="' + this.arg + ': ' + | ||
this.expression + '" expects a function value, ' + | ||
'got ' + handler | ||
) | ||
@@ -29,0 +30,0 @@ return |
@@ -21,31 +21,13 @@ // NOTE: the prop internal directive is compiled and linked | ||
// simple lock to avoid circular updates. | ||
// without this it would stabilize too, but this makes | ||
// sure it doesn't cause other watchers to re-evaluate. | ||
var locked = false | ||
function withLock (fn) { | ||
return function (val) { | ||
if (!locked) { | ||
locked = true | ||
fn(val) | ||
_.nextTick(function () { | ||
locked = false | ||
}) | ||
} | ||
} | ||
} | ||
this.parentWatcher = new Watcher( | ||
parent, | ||
parentKey, | ||
withLock(function (val) { | ||
function (val) { | ||
if (_.assertProp(prop, val)) { | ||
child[childKey] = val | ||
} | ||
}) | ||
} | ||
) | ||
// set the child initial value. | ||
// !!! We need to set it also on raw data here, because | ||
// props are initialized before data is fully observed | ||
var value = this.parentWatcher.value | ||
@@ -58,4 +40,3 @@ if (childKey === '$data') { | ||
// only setup two-way binding if this is not a one-way | ||
// binding. | ||
// setup two-way binding | ||
if (prop.mode === bindingModes.TWO_WAY) { | ||
@@ -69,5 +50,5 @@ // important: defer the child watcher creation until | ||
childKey, | ||
withLock(function (val) { | ||
function (val) { | ||
parent.$set(parentKey, val) | ||
}) | ||
} | ||
) | ||
@@ -79,5 +60,3 @@ }) | ||
unbind: function () { | ||
if (this.parentWatcher) { | ||
this.parentWatcher.teardown() | ||
} | ||
this.parentWatcher.teardown() | ||
if (this.childWatcher) { | ||
@@ -84,0 +63,0 @@ this.childWatcher.teardown() |
@@ -10,3 +10,3 @@ var _ = require('../util') | ||
if (!vm) { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'v-ref should only be used on a component root element.' | ||
@@ -13,0 +13,0 @@ ) |
@@ -23,2 +23,8 @@ var _ = require('../util') | ||
bind: function () { | ||
// support for item in array syntax | ||
var inMatch = this.expression.match(/(.*) in (.*)/) | ||
if (inMatch) { | ||
this.arg = inMatch[1] | ||
this._watcherExp = inMatch[2] | ||
} | ||
// uid as a cache identifier | ||
@@ -49,2 +55,14 @@ this.id = '__v_repeat_' + (++uid) | ||
this.cache = Object.create(null) | ||
// some helpful tips... | ||
/* istanbul ignore if */ | ||
if ( | ||
process.env.NODE_ENV !== 'production' && | ||
this.el.tagName === 'OPTION' | ||
) { | ||
_.warn( | ||
'Don\'t use v-repeat for v-model options; ' + | ||
'use the `options` param instead: ' + | ||
'http://vuejs.org/guide/forms.html#Dynamic_Select_Options' | ||
) | ||
} | ||
}, | ||
@@ -58,3 +76,3 @@ | ||
if (_.attr(this.el, 'if') !== null) { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Don\'t use v-if with v-repeat. ' + | ||
@@ -161,5 +179,7 @@ 'Use v-show or the "filterBy" filter instead.' | ||
var Ctor = _.resolveAsset(this.vm.$options, 'components', id) | ||
_.assertAsset(Ctor, 'component', id) | ||
if (process.env.NODE_ENV !== 'production') { | ||
_.assertAsset(Ctor, 'component', id) | ||
} | ||
if (!Ctor.options) { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Async resolution is not supported for v-repeat ' + | ||
@@ -387,3 +407,3 @@ '+ dynamic component. (component: ' + id + ')' | ||
if (dir.filters) { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'You seem to be mutating the $value reference of ' + | ||
@@ -457,3 +477,5 @@ 'a v-repeat instance (likely through v-model) ' + | ||
} else if (!primitive && idKey !== '$index') { | ||
_.warn('Duplicate track-by key in v-repeat: ' + id) | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Duplicate track-by key in v-repeat: ' + id | ||
) | ||
} | ||
@@ -466,3 +488,3 @@ } else { | ||
} else { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Duplicate objects are not supported in v-repeat ' + | ||
@@ -531,44 +553,2 @@ 'when using components or transitions.' | ||
/** | ||
* Pre-process the value before piping it through the | ||
* filters, and convert non-Array objects to arrays. | ||
* | ||
* This function will be bound to this directive instance | ||
* and passed into the watcher. | ||
* | ||
* @param {*} value | ||
* @return {Array} | ||
* @private | ||
*/ | ||
_preProcess: function (value) { | ||
// regardless of type, store the un-filtered raw value. | ||
this.rawValue = value | ||
var type = this.rawType = typeof value | ||
if (!isPlainObject(value)) { | ||
this.converted = false | ||
if (type === 'number') { | ||
value = range(value) | ||
} else if (type === 'string') { | ||
value = _.toArray(value) | ||
} | ||
return value || [] | ||
} else { | ||
// convert plain object to array. | ||
var keys = Object.keys(value) | ||
var i = keys.length | ||
var res = new Array(i) | ||
var key | ||
while (i--) { | ||
key = keys[i] | ||
res[i] = { | ||
$key: key, | ||
$value: value[key] | ||
} | ||
} | ||
this.converted = true | ||
return res | ||
} | ||
}, | ||
/** | ||
* Insert an instance. | ||
@@ -673,4 +653,45 @@ * | ||
: index * this[type] | ||
}, | ||
/** | ||
* Pre-process the value before piping it through the | ||
* filters, and convert non-Array objects to arrays. | ||
* | ||
* This function will be bound to this directive instance | ||
* and passed into the watcher. | ||
* | ||
* @param {*} value | ||
* @return {Array} | ||
* @private | ||
*/ | ||
_preProcess: function (value) { | ||
// regardless of type, store the un-filtered raw value. | ||
this.rawValue = value | ||
var type = this.rawType = typeof value | ||
if (!isPlainObject(value)) { | ||
this.converted = false | ||
if (type === 'number') { | ||
value = range(value) | ||
} else if (type === 'string') { | ||
value = _.toArray(value) | ||
} | ||
return value || [] | ||
} else { | ||
// convert plain object to array. | ||
var keys = Object.keys(value) | ||
var i = keys.length | ||
var res = new Array(i) | ||
var key | ||
while (i--) { | ||
key = keys[i] | ||
res[i] = { | ||
$key: key, | ||
$value: value[key] | ||
} | ||
} | ||
this.converted = true | ||
return res | ||
} | ||
} | ||
} | ||
@@ -695,2 +716,4 @@ | ||
var el = vm.$el.previousSibling | ||
/* istanbul ignore if */ | ||
if (!el) return | ||
while ( | ||
@@ -697,0 +720,0 @@ (!el.__vue__ || el.__vue__.$options._repeatId !== id) && |
@@ -48,3 +48,5 @@ var _ = require('../util') | ||
var partial = _.resolveAsset(this.vm.$options, 'partials', id) | ||
_.assertAsset(partial, 'partial', id) | ||
if (process.env.NODE_ENV !== 'production') { | ||
_.assertAsset(partial, 'partial', id) | ||
} | ||
if (partial) { | ||
@@ -51,0 +53,0 @@ var frag = templateParser.parse(partial, true) |
@@ -59,3 +59,3 @@ var _ = require('../util') | ||
} else { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Unknown method: "' + handler + '" when ' + | ||
@@ -62,0 +62,0 @@ 'registering callback for ' + action + |
@@ -21,3 +21,5 @@ var _ = require('../util') | ||
fn = _.resolveAsset(this.$options, 'filters', filter.name) | ||
_.assertAsset(fn, 'filter', filter.name) | ||
if (process.env.NODE_ENV !== 'production') { | ||
_.assertAsset(fn, 'filter', filter.name) | ||
} | ||
if (!fn) continue | ||
@@ -54,3 +56,5 @@ fn = write ? fn.write : (fn.read || fn) | ||
var factory = _.resolveAsset(this.$options, 'components', id) | ||
_.assertAsset(factory, 'component', id) | ||
if (process.env.NODE_ENV !== 'production') { | ||
_.assertAsset(factory, 'component', id) | ||
} | ||
// async component factory | ||
@@ -78,3 +82,3 @@ if (!factory.options) { | ||
}, function reject (reason) { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Failed to resolve async component: ' + id + '. ' + | ||
@@ -81,0 +85,0 @@ (reason ? '\nReason: ' + reason : '') |
@@ -5,2 +5,3 @@ var _ = require('../util') | ||
var Dep = require('../observer/dep') | ||
var Watcher = require('../watcher') | ||
@@ -32,3 +33,3 @@ /** | ||
if (props && !el) { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Props will not be compiled if no `el` option is ' + | ||
@@ -58,3 +59,6 @@ 'provided at instantiation.' | ||
for (var prop in propsData) { | ||
if (this._props[prop].raw !== null) { | ||
if ( | ||
this._props[prop].raw !== null || | ||
!optionsData.hasOwnProperty(prop) | ||
) { | ||
optionsData.$set(prop, propsData[prop]) | ||
@@ -197,7 +201,7 @@ } | ||
if (typeof userDef === 'function') { | ||
def.get = _.bind(userDef, this) | ||
def.get = makeComputedGetter(userDef, this) | ||
def.set = noop | ||
} else { | ||
def.get = userDef.get | ||
? _.bind(userDef.get, this) | ||
? makeComputedGetter(userDef.get, this) | ||
: noop | ||
@@ -213,2 +217,17 @@ def.set = userDef.set | ||
function makeComputedGetter (getter, owner) { | ||
var watcher = new Watcher(owner, getter, null, { | ||
lazy: true | ||
}) | ||
return function computedGetter () { | ||
if (watcher.dirty) { | ||
watcher.evaluate() | ||
} | ||
if (Dep.target) { | ||
watcher.depend() | ||
} | ||
return watcher.value | ||
} | ||
} | ||
/** | ||
@@ -256,3 +275,5 @@ * Setup instance methods. Methods must be bound to the | ||
get: function metaGetter () { | ||
dep.depend() | ||
if (Dep.target) { | ||
dep.depend() | ||
} | ||
return value | ||
@@ -259,0 +280,0 @@ }, |
@@ -45,3 +45,3 @@ var _ = require('../util') | ||
// notify change | ||
ob.notify() | ||
ob.dep.notify() | ||
return result | ||
@@ -48,0 +48,0 @@ }) |
@@ -46,5 +46,3 @@ var _ = require('../util') | ||
p.depend = function () { | ||
if (Dep.target) { | ||
Dep.target.addDep(this) | ||
} | ||
Dep.target.addDep(this) | ||
} | ||
@@ -51,0 +49,0 @@ |
@@ -20,4 +20,3 @@ var _ = require('../util') | ||
this.value = value | ||
this.active = true | ||
this.deps = [] | ||
this.dep = new Dep() | ||
_.define(value, '__ob__', this) | ||
@@ -69,12 +68,2 @@ if (_.isArray(value)) { | ||
/** | ||
* Set the target watcher that is currently being evaluated. | ||
* | ||
* @param {Watcher} watcher | ||
*/ | ||
Observer.setTarget = function (watcher) { | ||
Dep.target = watcher | ||
} | ||
// Instance methods | ||
@@ -143,5 +132,2 @@ | ||
var dep = new Dep() | ||
if (childOb) { | ||
childOb.deps.push(dep) | ||
} | ||
Object.defineProperty(ob.value, key, { | ||
@@ -151,4 +137,13 @@ enumerable: true, | ||
get: function () { | ||
if (ob.active) { | ||
if (Dep.target) { | ||
dep.depend() | ||
if (childOb) { | ||
childOb.dep.depend() | ||
} | ||
if (_.isArray(val)) { | ||
for (var e, i = 0, l = val.length; i < l; i++) { | ||
e = val[i] | ||
e && e.__ob__ && e.__ob__.dep.depend() | ||
} | ||
} | ||
} | ||
@@ -159,13 +154,4 @@ return val | ||
if (newVal === val) return | ||
// remove dep from old value | ||
var oldChildOb = val && val.__ob__ | ||
if (oldChildOb) { | ||
oldChildOb.deps.$remove(dep) | ||
} | ||
val = newVal | ||
// add dep to new value | ||
var newChildOb = ob.observe(newVal) | ||
if (newChildOb) { | ||
newChildOb.deps.push(dep) | ||
} | ||
childOb = ob.observe(newVal) | ||
dep.notify() | ||
@@ -177,16 +163,2 @@ } | ||
/** | ||
* Notify change on all self deps on an observer. | ||
* This is called when a mutable value mutates. e.g. | ||
* when an Array's mutating methods are called, or an | ||
* Object's $add/$delete are called. | ||
*/ | ||
p.notify = function () { | ||
var deps = this.deps | ||
for (var i = 0, l = deps.length; i < l; i++) { | ||
deps[i].notify() | ||
} | ||
} | ||
/** | ||
* Add an owner vm, so that when $add/$delete mutations | ||
@@ -193,0 +165,0 @@ * happen we can notify owner vms to proxy the keys and |
@@ -24,3 +24,3 @@ var _ = require('../util') | ||
ob.convert(key, val) | ||
ob.notify() | ||
ob.dep.notify() | ||
if (ob.vms) { | ||
@@ -73,3 +73,3 @@ var i = ob.vms.length | ||
} | ||
ob.notify() | ||
ob.dep.notify() | ||
if (ob.vms) { | ||
@@ -76,0 +76,0 @@ var i = ob.vms.length |
@@ -109,3 +109,3 @@ var _ = require('../util') | ||
if (improperKeywordsRE.test(exp)) { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Avoid using reserved keywords in expression: ' + exp | ||
@@ -179,3 +179,3 @@ ) | ||
} catch (e) { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Invalid expression. ' + | ||
@@ -205,3 +205,5 @@ 'Generated function body: ' + body | ||
} catch (e) { | ||
_.warn('Invalid setter function body: ' + body) | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Invalid setter function body: ' + body | ||
) | ||
} | ||
@@ -208,0 +210,0 @@ } |
@@ -6,78 +6,98 @@ var _ = require('../util') | ||
/** | ||
* Path-parsing algorithm scooped from Polymer/observe-js | ||
*/ | ||
// actions | ||
var APPEND = 0 | ||
var PUSH = 1 | ||
var pathStateMachine = { | ||
'beforePath': { | ||
'ws': ['beforePath'], | ||
'ident': ['inIdent', 'append'], | ||
'[': ['beforeElement'], | ||
'eof': ['afterPath'] | ||
}, | ||
// states | ||
var BEFORE_PATH = 0 | ||
var IN_PATH = 1 | ||
var BEFORE_IDENT = 2 | ||
var IN_IDENT = 3 | ||
var BEFORE_ELEMENT = 4 | ||
var AFTER_ZERO = 5 | ||
var IN_INDEX = 6 | ||
var IN_SINGLE_QUOTE = 7 | ||
var IN_DOUBLE_QUOTE = 8 | ||
var IN_SUB_PATH = 9 | ||
var AFTER_ELEMENT = 10 | ||
var AFTER_PATH = 11 | ||
var ERROR = 12 | ||
'inPath': { | ||
'ws': ['inPath'], | ||
'.': ['beforeIdent'], | ||
'[': ['beforeElement'], | ||
'eof': ['afterPath'] | ||
}, | ||
var pathStateMachine = [] | ||
'beforeIdent': { | ||
'ws': ['beforeIdent'], | ||
'ident': ['inIdent', 'append'] | ||
}, | ||
pathStateMachine[BEFORE_PATH] = { | ||
'ws': [BEFORE_PATH], | ||
'ident': [IN_IDENT, APPEND], | ||
'[': [BEFORE_ELEMENT], | ||
'eof': [AFTER_PATH] | ||
} | ||
'inIdent': { | ||
'ident': ['inIdent', 'append'], | ||
'0': ['inIdent', 'append'], | ||
'number': ['inIdent', 'append'], | ||
'ws': ['inPath', 'push'], | ||
'.': ['beforeIdent', 'push'], | ||
'[': ['beforeElement', 'push'], | ||
'eof': ['afterPath', 'push'], | ||
']': ['inPath', 'push'] | ||
}, | ||
pathStateMachine[IN_PATH] = { | ||
'ws': [IN_PATH], | ||
'.': [BEFORE_IDENT], | ||
'[': [BEFORE_ELEMENT], | ||
'eof': [AFTER_PATH] | ||
} | ||
'beforeElement': { | ||
'ws': ['beforeElement'], | ||
'0': ['afterZero', 'append'], | ||
'number': ['inIndex', 'append'], | ||
"'": ['inSingleQuote', 'append', ''], | ||
'"': ['inDoubleQuote', 'append', ''], | ||
'ident': ['inIdent', 'append', '*'] | ||
}, | ||
pathStateMachine[BEFORE_IDENT] = { | ||
'ws': [BEFORE_IDENT], | ||
'ident': [IN_IDENT, APPEND] | ||
} | ||
'afterZero': { | ||
'ws': ['afterElement', 'push'], | ||
']': ['inPath', 'push'] | ||
}, | ||
pathStateMachine[IN_IDENT] = { | ||
'ident': [IN_IDENT, APPEND], | ||
'0': [IN_IDENT, APPEND], | ||
'number': [IN_IDENT, APPEND], | ||
'ws': [IN_PATH, PUSH], | ||
'.': [BEFORE_IDENT, PUSH], | ||
'[': [BEFORE_ELEMENT, PUSH], | ||
'eof': [AFTER_PATH, PUSH] | ||
} | ||
'inIndex': { | ||
'0': ['inIndex', 'append'], | ||
'number': ['inIndex', 'append'], | ||
'ws': ['afterElement'], | ||
']': ['inPath', 'push'] | ||
}, | ||
pathStateMachine[BEFORE_ELEMENT] = { | ||
'ws': [BEFORE_ELEMENT], | ||
'0': [AFTER_ZERO, APPEND], | ||
'number': [IN_INDEX, APPEND], | ||
"'": [IN_SINGLE_QUOTE, APPEND, ''], | ||
'"': [IN_DOUBLE_QUOTE, APPEND, ''], | ||
'ident': [IN_SUB_PATH, APPEND, '*'] | ||
} | ||
'inSingleQuote': { | ||
"'": ['afterElement'], | ||
'eof': 'error', | ||
'else': ['inSingleQuote', 'append'] | ||
}, | ||
pathStateMachine[AFTER_ZERO] = { | ||
'ws': [AFTER_ELEMENT, PUSH], | ||
']': [IN_PATH, PUSH] | ||
} | ||
'inDoubleQuote': { | ||
'"': ['afterElement'], | ||
'eof': 'error', | ||
'else': ['inDoubleQuote', 'append'] | ||
}, | ||
pathStateMachine[IN_INDEX] = { | ||
'0': [IN_INDEX, APPEND], | ||
'number': [IN_INDEX, APPEND], | ||
'ws': [AFTER_ELEMENT], | ||
']': [IN_PATH, PUSH] | ||
} | ||
'afterElement': { | ||
'ws': ['afterElement'], | ||
']': ['inPath', 'push'] | ||
} | ||
pathStateMachine[IN_SINGLE_QUOTE] = { | ||
"'": [AFTER_ELEMENT], | ||
'eof': ERROR, | ||
'else': [IN_SINGLE_QUOTE, APPEND] | ||
} | ||
function noop () {} | ||
pathStateMachine[IN_DOUBLE_QUOTE] = { | ||
'"': [AFTER_ELEMENT], | ||
'eof': ERROR, | ||
'else': [IN_DOUBLE_QUOTE, APPEND] | ||
} | ||
pathStateMachine[IN_SUB_PATH] = { | ||
'ident': [IN_SUB_PATH, APPEND], | ||
'0': [IN_SUB_PATH, APPEND], | ||
'number': [IN_SUB_PATH, APPEND], | ||
'ws': [AFTER_ELEMENT], | ||
']': [IN_PATH, PUSH] | ||
} | ||
pathStateMachine[AFTER_ELEMENT] = { | ||
'ws': [AFTER_ELEMENT], | ||
']': [IN_PATH, PUSH] | ||
} | ||
/** | ||
@@ -148,29 +168,28 @@ * Determine the type of a character in a keypath. | ||
var index = -1 | ||
var mode = 'beforePath' | ||
var mode = BEFORE_PATH | ||
var c, newChar, key, type, transition, action, typeMap | ||
var actions = { | ||
push: function () { | ||
if (key === undefined) { | ||
return | ||
} | ||
keys.push(key) | ||
key = undefined | ||
}, | ||
append: function () { | ||
if (key === undefined) { | ||
key = newChar | ||
} else { | ||
key += newChar | ||
} | ||
var actions = [] | ||
actions[PUSH] = function () { | ||
if (key === undefined) { | ||
return | ||
} | ||
keys.push(key) | ||
key = undefined | ||
} | ||
actions[APPEND] = function () { | ||
if (key === undefined) { | ||
key = newChar | ||
} else { | ||
key += newChar | ||
} | ||
} | ||
function maybeUnescapeQuote () { | ||
var nextChar = path[index + 1] | ||
if ((mode === 'inSingleQuote' && nextChar === "'") || | ||
(mode === 'inDoubleQuote' && nextChar === '"')) { | ||
if ((mode === IN_SINGLE_QUOTE && nextChar === "'") || | ||
(mode === IN_DOUBLE_QUOTE && nextChar === '"')) { | ||
index++ | ||
newChar = nextChar | ||
actions.append() | ||
actions[APPEND]() | ||
return true | ||
@@ -180,3 +199,3 @@ } | ||
while (mode) { | ||
while (mode != null) { | ||
index++ | ||
@@ -191,5 +210,5 @@ c = path[index] | ||
typeMap = pathStateMachine[mode] | ||
transition = typeMap[type] || typeMap['else'] || 'error' | ||
transition = typeMap[type] || typeMap['else'] || ERROR | ||
if (transition === 'error') { | ||
if (transition === ERROR) { | ||
return // parse error | ||
@@ -199,12 +218,14 @@ } | ||
mode = transition[0] | ||
action = actions[transition[1]] || noop | ||
newChar = transition[2] | ||
newChar = newChar === undefined | ||
? c | ||
: newChar === '*' | ||
? newChar + c | ||
: newChar | ||
action() | ||
action = actions[transition[1]] | ||
if (action) { | ||
newChar = transition[2] | ||
newChar = newChar === undefined | ||
? c | ||
: newChar === '*' | ||
? newChar + c | ||
: newChar | ||
action() | ||
} | ||
if (mode === 'afterPath') { | ||
if (mode === AFTER_PATH) { | ||
keys.raw = path | ||
@@ -307,5 +328,5 @@ return keys | ||
if (!_.isObject(obj)) { | ||
warnNonExistent(path) | ||
obj = {} | ||
last.$add(key, obj) | ||
warnNonExistent(path) | ||
} | ||
@@ -318,4 +339,4 @@ } else { | ||
} else { | ||
warnNonExistent(path) | ||
obj.$add(key, val) | ||
warnNonExistent(path) | ||
} | ||
@@ -328,3 +349,3 @@ } | ||
function warnNonExistent (path) { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'You are setting a non-existent path "' + path.raw + '" ' + | ||
@@ -331,0 +352,0 @@ 'on a vm instance. Consider pre-initializing the property ' + |
@@ -142,3 +142,3 @@ var _ = require('../util') | ||
this.callHookWithCb('leave') | ||
this.cancel = this.hooks && this.hooks.enterCancelled | ||
this.cancel = this.hooks && this.hooks.leaveCancelled | ||
// only need to do leaveNextTick if there's no explicit | ||
@@ -145,0 +145,0 @@ // js callback |
@@ -62,2 +62,7 @@ var _ = require('./index') | ||
exports.assertProp = function (prop, value) { | ||
// if a prop is not provided and is not required, | ||
// skip the check. | ||
if (prop.raw === null && !prop.required) { | ||
return true | ||
} | ||
var options = prop.options | ||
@@ -91,3 +96,3 @@ var type = options.type | ||
if (!valid) { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Invalid prop: type check failed for ' + | ||
@@ -103,3 +108,3 @@ prop.path + '="' + prop.raw + '".' + | ||
if (!validator.call(null, value)) { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Invalid prop: custom validator check failed for ' + | ||
@@ -106,0 +111,0 @@ prop.path + '="' + prop.raw + '"' |
@@ -1,13 +0,8 @@ | ||
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. | ||
*/ | ||
enableDebug() | ||
if (process.env.NODE_ENV !== 'production') { | ||
function enableDebug () { | ||
var config = require('../config') | ||
var hasConsole = typeof console !== 'undefined' | ||
@@ -14,0 +9,0 @@ |
@@ -16,3 +16,5 @@ var _ = require('./index') | ||
if (!el) { | ||
_.warn('Cannot find element: ' + selector) | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Cannot find element: ' + selector | ||
) | ||
} | ||
@@ -19,0 +21,0 @@ } |
var _ = require('./index') | ||
var config = require('../config') | ||
var extend = _.extend | ||
@@ -47,3 +48,3 @@ | ||
if (typeof childVal !== 'function') { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'The "data" option should be a function ' + | ||
@@ -93,3 +94,3 @@ 'that returns a per-instance value in component ' + | ||
if (!vm && childVal && typeof childVal !== 'function') { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'The "el" option should be a function ' + | ||
@@ -136,3 +137,3 @@ 'that returns a per-instance value in component ' + | ||
/* istanbul ignore next */ | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'"paramAttributes" option has been deprecated in 0.12. ' + | ||
@@ -151,14 +152,13 @@ 'Use "props" instead.' | ||
strats.directives = | ||
strats.filters = | ||
strats.transitions = | ||
strats.components = | ||
strats.partials = | ||
strats.elementDirectives = function (parentVal, childVal) { | ||
function mergeAssets (parentVal, childVal) { | ||
var res = Object.create(parentVal) | ||
return childVal | ||
? extend(res, childVal) | ||
? extend(res, guardArrayAssets(childVal)) | ||
: res | ||
} | ||
config._assetTypes.forEach(function (type) { | ||
strats[type + 's'] = mergeAssets | ||
}) | ||
/** | ||
@@ -217,19 +217,24 @@ * Events & Watchers. | ||
* | ||
* @param {Object} components | ||
* @param {Object} options | ||
*/ | ||
function guardComponents (components) { | ||
if (components) { | ||
function guardComponents (options) { | ||
if (options.components) { | ||
var components = options.components = | ||
guardArrayAssets(options.components) | ||
var def | ||
for (var key in components) { | ||
var ids = Object.keys(components) | ||
for (var i = 0, l = ids.length; i < l; i++) { | ||
var key = ids[i] | ||
if (_.commonTagRE.test(key)) { | ||
_.warn( | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Do not use built-in HTML elements as component ' + | ||
'name: ' + key | ||
'id: ' + key | ||
) | ||
continue | ||
} | ||
def = components[key] | ||
if (_.isPlainObject(def)) { | ||
def.name = key | ||
components[key] = _.Vue.extend(def) | ||
def.id = def.id || key | ||
components[key] = def._Ctor || (def._Ctor = _.Vue.extend(def)) | ||
} | ||
@@ -268,2 +273,31 @@ } | ||
/** | ||
* Guard an Array-format assets option and converted it | ||
* into the key-value Object format. | ||
* | ||
* @param {Object|Array} assets | ||
* @return {Object} | ||
*/ | ||
function guardArrayAssets (assets) { | ||
if (_.isArray(assets)) { | ||
var res = {} | ||
var i = assets.length | ||
var asset | ||
while (i--) { | ||
asset = assets[i] | ||
var id = asset.id || (asset.options && asset.options.id) | ||
if (!id) { | ||
process.env.NODE_ENV !== 'production' && _.warn( | ||
'Array-syntax assets must provide an id field.' | ||
) | ||
} else { | ||
res[id] = asset | ||
} | ||
} | ||
return res | ||
} | ||
return assets | ||
} | ||
/** | ||
* Merge two option objects into a new one. | ||
@@ -279,3 +313,3 @@ * Core utility used in both instantiation and inheritance. | ||
exports.mergeOptions = function merge (parent, child, vm) { | ||
guardComponents(child.components) | ||
guardComponents(child) | ||
guardProps(child) | ||
@@ -317,3 +351,3 @@ var options = {} | ||
var asset = options[type][id] | ||
while (!asset && options._parent) { | ||
while (!config.strict && !asset && options._parent) { | ||
options = options._parent.$options | ||
@@ -320,0 +354,0 @@ asset = options[type][id] |
var _ = require('./util') | ||
var config = require('./config') | ||
var Observer = require('./observer') | ||
var Dep = require('./observer/dep') | ||
var expParser = require('./parsers/expression') | ||
@@ -21,2 +21,3 @@ var batcher = require('./batcher') | ||
* - {Boolean} user | ||
* - {Boolean} lazy | ||
* - {Function} [preProcess] | ||
@@ -38,6 +39,8 @@ * @constructor | ||
this.twoWay = !!options.twoWay | ||
this.lazy = !!options.lazy | ||
this.dirty = this.lazy | ||
this.filters = options.filters | ||
this.preProcess = options.preProcess | ||
this.deps = [] | ||
this.newDeps = [] | ||
this.newDeps = null | ||
// parse expression for getter/setter | ||
@@ -52,3 +55,5 @@ if (isFn) { | ||
} | ||
this.value = this.get() | ||
this.value = this.lazy | ||
? undefined | ||
: this.get() | ||
// state for avoiding false triggers for deep and Array | ||
@@ -92,3 +97,6 @@ // watchers during vm._digest() | ||
} catch (e) { | ||
if (config.warnExpressionErrors) { | ||
if ( | ||
process.env.NODE_ENV !== 'production' && | ||
config.warnExpressionErrors | ||
) { | ||
_.warn( | ||
@@ -134,3 +142,6 @@ 'Error when evaluating expression "' + | ||
} catch (e) { | ||
if (config.warnExpressionErrors) { | ||
if ( | ||
process.env.NODE_ENV !== 'production' && | ||
config.warnExpressionErrors | ||
) { | ||
_.warn( | ||
@@ -149,3 +160,4 @@ 'Error when evaluating setter "' + | ||
p.beforeGet = function () { | ||
Observer.setTarget(this) | ||
Dep.target = this | ||
this.newDeps = [] | ||
} | ||
@@ -158,3 +170,3 @@ | ||
p.afterGet = function () { | ||
Observer.setTarget(null) | ||
Dep.target = null | ||
var i = this.deps.length | ||
@@ -168,3 +180,3 @@ while (i--) { | ||
this.deps = this.newDeps | ||
this.newDeps = [] | ||
this.newDeps = null | ||
} | ||
@@ -180,3 +192,5 @@ | ||
p.update = function (shallow) { | ||
if (!config.async) { | ||
if (this.lazy) { | ||
this.dirty = true | ||
} else if (!config.async) { | ||
this.run() | ||
@@ -221,2 +235,27 @@ } else { | ||
/** | ||
* Evaluate the value of the watcher. | ||
* This only gets called for lazy watchers. | ||
*/ | ||
p.evaluate = function () { | ||
// avoid overwriting another watcher that is being | ||
// collected. | ||
var current = Dep.target | ||
this.value = this.get() | ||
this.dirty = false | ||
Dep.target = current | ||
} | ||
/** | ||
* Depend on all deps collected by this watcher. | ||
*/ | ||
p.depend = function () { | ||
var i = this.deps.length | ||
while (i--) { | ||
this.deps[i].depend() | ||
} | ||
} | ||
/** | ||
* Remove self from all dependencies' subcriber list. | ||
@@ -223,0 +262,0 @@ */ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
523519
17503
1
46
+ Addedenvify@^3.4.0
+ Addedacorn@5.7.4(transitive)
+ Addedamdefine@1.0.1(transitive)
+ Addedast-types@0.9.6(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbase62@1.2.8(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedcommoner@0.10.8(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addeddefined@1.0.1(transitive)
+ Addeddetective@4.7.1(transitive)
+ Addedenvify@3.4.1(transitive)
+ Addedesprima@3.1.3(transitive)
+ Addedesprima-fb@15001.1.0-dev-harmony-fb(transitive)
+ Addedglob@5.0.15(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedjstransform@11.0.3(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedobject-assign@2.1.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedprivate@0.1.8(transitive)
+ Addedq@1.5.1(transitive)
+ Addedrecast@0.11.23(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsource-map@0.4.40.5.7(transitive)
+ Addedthrough@2.3.8(transitive)
+ Addedwrappy@1.0.2(transitive)