mirror of https://github.com/vuejs/vue.git
more tuning
This commit is contained in:
parent
ef7430d5b4
commit
77c9b8bfe7
|
|
@ -45,6 +45,11 @@ exports._init = function (options) {
|
||||||
this._children = []
|
this._children = []
|
||||||
if (this.$parent) {
|
if (this.$parent) {
|
||||||
this.$parent._children.push(this)
|
this.$parent._children.push(this)
|
||||||
|
var root = this.$parent
|
||||||
|
while (root.$parent) {
|
||||||
|
root = root.$parent
|
||||||
|
}
|
||||||
|
this.$root = root
|
||||||
}
|
}
|
||||||
|
|
||||||
// merge options.
|
// merge options.
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,10 @@ exports._initScope = function () {
|
||||||
? Object.create(parent.$scope)
|
? Object.create(parent.$scope)
|
||||||
: {}
|
: {}
|
||||||
// copy initial data into scope
|
// copy initial data into scope
|
||||||
for (var key in data) {
|
var keys = Object.keys(data)
|
||||||
|
for (var key, i = 0, l = keys.length; i < l; i++) {
|
||||||
// use defineProperty so we can shadow parent accessors
|
// use defineProperty so we can shadow parent accessors
|
||||||
|
key = keys[i]
|
||||||
_.define(scope, key, data[key], true)
|
_.define(scope, key, data[key], true)
|
||||||
}
|
}
|
||||||
// create scope observer
|
// create scope observer
|
||||||
|
|
@ -138,10 +140,9 @@ exports._initProxy = function () {
|
||||||
// scope --> vm
|
// scope --> vm
|
||||||
|
|
||||||
// proxy scope data on vm
|
// proxy scope data on vm
|
||||||
for (var key in scope) {
|
var keys = Object.keys(scope)
|
||||||
if (scope.hasOwnProperty(key)) {
|
for (var i = 0, l = keys.length; i < l; i++) {
|
||||||
_.proxy(this, scope, key)
|
_.proxy(this, scope, keys[i])
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// keep proxying up-to-date with added/deleted keys.
|
// keep proxying up-to-date with added/deleted keys.
|
||||||
this.$observer
|
this.$observer
|
||||||
|
|
@ -154,9 +155,10 @@ exports._initProxy = function () {
|
||||||
|
|
||||||
// vm --> scope
|
// vm --> scope
|
||||||
|
|
||||||
// proxy vm parent & root on scope
|
// $parent & $root are read-only on $scope
|
||||||
_.proxy(scope, this, '$parent')
|
scope.$parent = this.$parent
|
||||||
_.proxy(scope, this, '$root')
|
scope.$root = this.$root
|
||||||
|
// proxy $data
|
||||||
_.proxy(scope, this, '$data')
|
_.proxy(scope, this, '$data')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
14
src/vue.js
14
src/vue.js
|
|
@ -48,20 +48,6 @@ Vue.options = {
|
||||||
|
|
||||||
var p = Vue.prototype
|
var p = Vue.prototype
|
||||||
|
|
||||||
/**
|
|
||||||
* The $root recursively points to the root instance.
|
|
||||||
*
|
|
||||||
* @readonly
|
|
||||||
*/
|
|
||||||
|
|
||||||
Object.defineProperty(p, '$root', {
|
|
||||||
get: function () {
|
|
||||||
return this.$parent
|
|
||||||
? this.$parent.$root
|
|
||||||
: this
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $data has a setter which does a bunch of
|
* $data has a setter which does a bunch of
|
||||||
* teardown/setup work
|
* teardown/setup work
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue