diff --git a/src/api/child.js b/src/api/child.js index d45507079..a1b9b7bc4 100644 --- a/src/api/child.js +++ b/src/api/child.js @@ -1,9 +1,7 @@ var _ = require('../util') /** - * Create a child instance that prototypally inherits - * data on parent. To achieve that we create an intermediate - * constructor with its prototype pointing to parent. + * Create a child instance. * * @param {Object} opts * @param {Function} [BaseCtor] @@ -12,36 +10,9 @@ var _ = require('../util') */ exports.$addChild = function (opts, BaseCtor) { - BaseCtor = BaseCtor || _.Vue - opts = opts || {} - var ChildVue + var ChildVue = BaseCtor || _.Vue var parent = this - // transclusion context - var context = opts._context || parent - var inherit = opts.inherit !== undefined - ? opts.inherit - : BaseCtor.options.inherit - if (inherit) { - var ctors = context._childCtors - ChildVue = ctors[BaseCtor.cid] - if (!ChildVue) { - var optionName = BaseCtor.options.name - var className = optionName - ? _.classify(optionName) - : 'VueComponent' - ChildVue = new Function( - 'return function ' + className + ' (options) {' + - 'this.constructor = ' + className + ';' + - 'this._init(options) }' - )() - ChildVue.options = BaseCtor.options - ChildVue.linker = BaseCtor.linker - ChildVue.prototype = context - ctors[BaseCtor.cid] = ChildVue - } - } else { - ChildVue = BaseCtor - } + opts = opts || {} opts._parent = parent opts._root = parent.$root var child = new ChildVue(opts) diff --git a/src/instance/init.js b/src/instance/init.js index 32ad5e4cb..969ac6af7 100644 --- a/src/instance/init.js +++ b/src/instance/init.js @@ -23,7 +23,6 @@ exports._init = function (options) { this.$$ = {} // element references this._watchers = [] // all watchers as an array this._directives = [] // all directives - this._childCtors = {} // inherit:true constructors // a flag to avoid this being observed this._isVue = true @@ -59,11 +58,6 @@ exports._init = function (options) { // and container directives. this._scope = options._scope - // set ref - if (options._ref) { - (this._scope || this._context).$[options._ref] = this - } - // fragment: // if this instance is compiled inside a Fragment, it // needs to reigster itself as a child of that fragment @@ -78,6 +72,11 @@ exports._init = function (options) { this.$parent.$children.push(this) } + // set ref + if (options._ref) { + (this._scope || this._context).$[options._ref] = this + } + // merge options. options = this.$options = mergeOptions( this.constructor.options, diff --git a/src/instance/state.js b/src/instance/state.js index 827b1c12f..a5f7ce475 100644 --- a/src/instance/state.js +++ b/src/instance/state.js @@ -156,18 +156,9 @@ exports._unproxy = function (key) { */ exports._digest = function () { - var i = this._watchers.length - while (i--) { + for (var i = 0, l = this._watchers.length; i < l; i++) { this._watchers[i].update(true) // shallow updates } - var children = this.$children - i = children.length - while (i--) { - var child = children[i] - if (child.$options.inherit) { - child._digest() - } - } } /** @@ -220,8 +211,8 @@ function makeComputedGetter (getter, owner) { /** * Setup instance methods. Methods must be bound to the - * instance since they might be called by children - * inheriting them. + * instance since they might be passed down as a prop to + * child components. */ exports._initMethods = function () { diff --git a/src/util/component.js b/src/util/component.js index f54651fd5..dc12d63b5 100644 --- a/src/util/component.js +++ b/src/util/component.js @@ -52,8 +52,6 @@ exports.checkComponent = function (el, options) { /** * Set a prop's initial value on a vm and its data object. - * The vm may have inherit:true so we need to make sure - * we don't accidentally overwrite parent value. * * @param {Vue} vm * @param {Object} prop @@ -63,12 +61,7 @@ exports.checkComponent = function (el, options) { exports.initProp = function (vm, prop, value) { if (exports.assertProp(prop, value)) { var key = prop.path - if (key in vm) { - _.define(vm, key, value, true) - } else { - vm[key] = value - } - vm._data[key] = value + vm[key] = vm._data[key] = value } } diff --git a/src/util/options.js b/src/util/options.js index 10656e3fe..a3e3db05f 100644 --- a/src/util/options.js +++ b/src/util/options.js @@ -304,13 +304,6 @@ function guardArrayAssets (assets) { */ exports.mergeOptions = function merge (parent, child, vm) { - - if (process.env.NODE_ENV !== 'production') { - if (child.inherit && !child._repeat) { - _.deprecation.INHERIT() - } - } - guardComponents(child) guardProps(child) var options = {} diff --git a/test/unit/specs/api/child_spec.js b/test/unit/specs/api/child_spec.js index cb5e547a3..50db5e163 100644 --- a/test/unit/specs/api/child_spec.js +++ b/test/unit/specs/api/child_spec.js @@ -23,55 +23,4 @@ describe('Child API', function () { expect(child.$root).toBe(vm) expect(vm.$children.indexOf(child)).toBe(0) }) - - it('inherit scope', function () { - var child = vm.$addChild({ - inherit: true, - data: { - b: 2 - } - }) - expect(child.a).toBe(1) - expect(child.b).toBe(2) - expect(child.constructor.prototype).toBe(vm) - }) - - it('with constructor', function () { - var Ctor = Vue.extend({ - inherit: true, - data: function () { - return { - c: 3 - } - } - }) - var child = vm.$addChild({ - data: { - b: 2 - } - }, Ctor) - expect(child.a).toBe(1) - expect(child.b).toBe(2) - expect(child.c).toBe(3) - expect(child.constructor.options).toBe(Ctor.options) - }) - - it('cache constructor', function () { - var Ctor = Vue.extend({ - inherit: true - }) - var child1 = vm.$addChild(null, Ctor) - var child2 = vm.$addChild(null, Ctor) - expect(child1.constructor).toBe(child2.constructor) - }) - - it('Use proper constructor name with inherit', function () { - var Ctor = Vue.extend({ - name: 'vue-test', - inherit: true - }) - var child = vm.$addChild(null, Ctor) - expect(child.constructor.toString().match(/^function VueTest\s?\(/)).toBeTruthy() - }) - }) diff --git a/test/unit/specs/directives/if_spec.js b/test/unit/specs/directives/if_spec.js index 5cba07e77..0562533a0 100644 --- a/test/unit/specs/directives/if_spec.js +++ b/test/unit/specs/directives/if_spec.js @@ -14,10 +14,10 @@ if (_.inBrowser) { var vm = new Vue({ el: el, data: { test: false, a: 'A' }, - template: '