Comparing version 0.12.5 to 0.12.6
{ | ||
"name": "vue", | ||
"version": "0.12.5", | ||
"version": "0.12.6", | ||
"author": "Evan You <yyx990803@gmail.com>", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -26,8 +26,7 @@ var _ = require('../util') | ||
this._callHook('compiled') | ||
this._initDOMHooks() | ||
if (_.inDoc(this.$el)) { | ||
this._callHook('attached') | ||
this._initDOMHooks() | ||
ready.call(this) | ||
} else { | ||
this._initDOMHooks() | ||
this.$once('hook:attached', ready) | ||
@@ -34,0 +33,0 @@ } |
var _ = require('../util') | ||
var compileProps = require('./compile-props') | ||
var config = require('../config') | ||
@@ -7,6 +8,2 @@ var textParser = require('../parsers/text') | ||
var resolveAsset = _.resolveAsset | ||
var propBindingModes = config._propBindingModes | ||
// internal directives | ||
var propDef = require('../directives/prop') | ||
var componentDef = require('../directives/component') | ||
@@ -251,3 +248,3 @@ | ||
if (!linkFn) { | ||
linkFn = checkComponent(el, options, hasAttrs) | ||
linkFn = checkComponent(el, options) | ||
} | ||
@@ -416,145 +413,2 @@ // normal directives | ||
/** | ||
* Compile param attributes on a root element and return | ||
* a props link function. | ||
* | ||
* @param {Element|DocumentFragment} el | ||
* @param {Array} propOptions | ||
* @return {Function} propsLinkFn | ||
*/ | ||
var dataAttrRE = /^data-/ | ||
var settablePathRE = /^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*|\[[^\[\]]+\])*$/ | ||
var literalValueRE = /^(true|false)$|^\d.*/ | ||
var identRE = require('../parsers/path').identRE | ||
function compileProps (el, propOptions) { | ||
var props = [] | ||
var i = propOptions.length | ||
var options, name, value, path, prop, literal, single | ||
while (i--) { | ||
options = propOptions[i] | ||
name = options.name | ||
// props could contain dashes, which will be | ||
// interpreted as minus calculations by the parser | ||
// so we need to camelize the path here | ||
path = _.camelize(name.replace(dataAttrRE, '')) | ||
if (/[A-Z]/.test(name)) { | ||
_.warn( | ||
'You seem to be using camelCase for a component prop, ' + | ||
'but HTML doesn\'t differentiate between upper and ' + | ||
'lower case. You should use hyphen-delimited ' + | ||
'attribute names. For more info see ' + | ||
'http://vuejs.org/api/options.html#props' | ||
) | ||
} | ||
if (!identRE.test(path)) { | ||
_.warn( | ||
'Invalid prop key: "' + name + '". Prop keys ' + | ||
'must be valid identifiers.' | ||
) | ||
} | ||
value = el.getAttribute(name) | ||
// create a prop descriptor | ||
prop = { | ||
name: name, | ||
raw: value, | ||
path: path, | ||
options: options, | ||
mode: propBindingModes.ONE_WAY | ||
} | ||
if (value !== null) { | ||
// important so that this doesn't get compiled | ||
// again as a normal attribute binding | ||
el.removeAttribute(name) | ||
var tokens = textParser.parse(value) | ||
if (tokens) { | ||
if (el && el.nodeType === 1) { | ||
el.removeAttribute(name) | ||
} | ||
prop.dynamic = true | ||
prop.parentPath = textParser.tokensToExp(tokens) | ||
// check prop binding type. | ||
single = tokens.length === 1 | ||
literal = literalValueRE.test(prop.parentPath) | ||
// one time: {{* prop}} | ||
if (literal || (single && tokens[0].oneTime)) { | ||
prop.mode = propBindingModes.ONE_TIME | ||
} else if ( | ||
!literal && | ||
(single && tokens[0].twoWay) | ||
) { | ||
if (settablePathRE.test(prop.parentPath)) { | ||
prop.mode = propBindingModes.TWO_WAY | ||
} else { | ||
_.warn( | ||
'Cannot bind two-way prop with non-settable ' + | ||
'parent path: ' + prop.parentPath | ||
) | ||
} | ||
} | ||
} | ||
} else if (options && options.required) { | ||
_.warn('Missing required prop: ' + name) | ||
} | ||
props.push(prop) | ||
} | ||
return makePropsLinkFn(props) | ||
} | ||
/** | ||
* Build a function that applies props to a vm. | ||
* | ||
* @param {Array} props | ||
* @return {Function} propsLinkFn | ||
*/ | ||
function makePropsLinkFn (props) { | ||
return function propsLinkFn (vm, el) { | ||
var i = props.length | ||
var prop, path, options, value | ||
while (i--) { | ||
prop = props[i] | ||
path = prop.path | ||
options = prop.options | ||
if (prop.raw === null) { | ||
// initialize absent prop | ||
vm._data[path] = options.type === Boolean | ||
? false | ||
: options.hasOwnProperty('default') | ||
? options.default | ||
: undefined | ||
} else if (prop.dynamic) { | ||
// dynamic prop | ||
if (vm._context) { | ||
if (prop.mode === propBindingModes.ONE_TIME) { | ||
// one time binding | ||
value = vm._context.$get(prop.parentPath) | ||
if (_.assertProp(prop, value)) { | ||
vm[path] = vm._data[path] = value | ||
} | ||
} else { | ||
// dynamic binding | ||
vm._bindDir('prop', el, prop, propDef) | ||
} | ||
} else { | ||
_.warn( | ||
'Cannot bind dynamic prop on a root instance' + | ||
' with no parent: ' + prop.name + '="' + | ||
prop.raw + '"' | ||
) | ||
} | ||
} else { | ||
// literal, cast it and just set once | ||
value = options.type === Boolean && prop.raw === '' | ||
? true | ||
: _.toBoolean(_.toNumber(prop.raw)) | ||
if (_.assertProp(prop, value)) { | ||
vm[path] = vm._data[path] = value | ||
} | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
* Check for element directives (custom elements that should | ||
@@ -561,0 +415,0 @@ * be resovled as terminal directives). |
@@ -68,2 +68,10 @@ var _ = require('../util') | ||
if (options.replace) { | ||
/* istanbul ignore if */ | ||
if (el === document.body) { | ||
_.warn( | ||
'You are mounting an instance with a template to ' + | ||
'<body>. This will replace <body> entirely. You ' + | ||
'should probably use `replace: false` here.' | ||
) | ||
} | ||
if ( | ||
@@ -70,0 +78,0 @@ // multi-children template |
@@ -104,3 +104,3 @@ var _ = require('../util') | ||
// just remove current | ||
this.unbuild() | ||
this.unbuild(true) | ||
this.remove(this.childVM, afterTransition) | ||
@@ -110,3 +110,3 @@ this.unsetCurrent() | ||
this.resolveCtor(value, _.bind(function () { | ||
this.unbuild() | ||
this.unbuild(true) | ||
var newComponent = this.build(data) | ||
@@ -195,5 +195,7 @@ /* istanbul ignore if */ | ||
* that we can separate the destroy and removal steps. | ||
* | ||
* @param {Boolean} defer | ||
*/ | ||
unbuild: function () { | ||
unbuild: function (defer) { | ||
var child = this.childVM | ||
@@ -206,3 +208,3 @@ if (!child || this.keepAlive) { | ||
// later. | ||
child.$destroy(false, true) | ||
child.$destroy(false, defer) | ||
}, | ||
@@ -292,2 +294,3 @@ | ||
this.invalidatePending() | ||
// Do not defer cleanup when unbinding | ||
this.unbuild() | ||
@@ -294,0 +297,0 @@ this.unsetCurrent() |
@@ -10,2 +10,8 @@ var _ = require('../../util') | ||
var el = this.el | ||
// update DOM using latest value. | ||
this.forceUpdate = function () { | ||
if (self._watcher) { | ||
self.update(self._watcher.get()) | ||
} | ||
} | ||
// check options param | ||
@@ -31,2 +37,7 @@ var optionsParam = this._checkParam('options') | ||
checkInitialValue.call(this) | ||
// All major browsers except Firefox resets | ||
// selectedIndex with value -1 to 0 when the element | ||
// is appended to a new parent, therefore we have to | ||
// force a DOM update whenever that happens... | ||
this.vm.$on('hook:attached', this.forceUpdate) | ||
}, | ||
@@ -53,2 +64,3 @@ | ||
_.off(this.el, 'change', this.listener) | ||
this.vm.$off('hook:attached', this.forceUpdate) | ||
if (this.optionWatcher) { | ||
@@ -74,5 +86,3 @@ this.optionWatcher.teardown() | ||
buildOptions(self.el, value) | ||
if (self._watcher) { | ||
self.update(self._watcher.value) | ||
} | ||
self.forceUpdate() | ||
} else { | ||
@@ -79,0 +89,0 @@ _.warn('Invalid options value for v-model: ' + value) |
@@ -7,3 +7,3 @@ var _ = require('../util') | ||
this.attr = this.el.nodeType === 3 | ||
? 'nodeValue' | ||
? 'data' | ||
: 'textContent' | ||
@@ -10,0 +10,0 @@ }, |
@@ -84,4 +84,6 @@ var _ = require('../util') | ||
function onAttached () { | ||
this._isAttached = true | ||
this.$children.forEach(callAttach) | ||
if (!this._isAttached) { | ||
this._isAttached = true | ||
this.$children.forEach(callAttach) | ||
} | ||
} | ||
@@ -106,4 +108,6 @@ | ||
function onDetached () { | ||
this._isAttached = false | ||
this.$children.forEach(callDetach) | ||
if (this._isAttached) { | ||
this._isAttached = false | ||
this.$children.forEach(callDetach) | ||
} | ||
} | ||
@@ -110,0 +114,0 @@ |
@@ -75,8 +75,12 @@ /** | ||
/** | ||
* Replace helper | ||
* Camelize a hyphen-delmited string. | ||
* | ||
* @param {String} _ - matched delimiter | ||
* @param {String} c - matched char | ||
* @param {String} str | ||
* @return {String} | ||
*/ | ||
exports.camelize = function (str) { | ||
return str.replace(/-(\w)/g, toUpper) | ||
} | ||
function toUpper (_, c) { | ||
@@ -87,3 +91,3 @@ return c ? c.toUpperCase() : '' | ||
/** | ||
* Camelize a hyphen-delmited string. | ||
* Hyphenate a camelCase string. | ||
* | ||
@@ -94,5 +98,6 @@ * @param {String} str | ||
var camelRE = /-(\w)/g | ||
exports.camelize = function (str) { | ||
return str.replace(camelRE, toUpper) | ||
exports.hyphenate = function (str) { | ||
return str | ||
.replace(/([a-z\d])([A-Z])/g, '$1-$2') | ||
.toLowerCase() | ||
} | ||
@@ -99,0 +104,0 @@ |
@@ -77,3 +77,2 @@ var _ = require('./index') | ||
* @param {Object} options | ||
* @param {Boolean} hasAttrs | ||
* @return {String|undefined} | ||
@@ -83,3 +82,3 @@ */ | ||
exports.commonTagRE = /^(div|p|span|img|a|br|ul|ol|li|h1|h2|h3|h4|h5|code|pre)$/ | ||
exports.checkComponent = function (el, options, hasAttrs) { | ||
exports.checkComponent = function (el, options) { | ||
var tag = el.tagName.toLowerCase() | ||
@@ -96,6 +95,5 @@ if (tag === 'component') { | ||
return tag | ||
} else if ( | ||
hasAttrs && | ||
(tag = _.attr(el, 'component')) | ||
) { | ||
/* eslint-disable no-cond-assign */ | ||
} else if (tag = _.attr(el, 'component')) { | ||
/* eslint-enable no-cond-assign */ | ||
return tag | ||
@@ -102,0 +100,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
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
508840
72
17057