Skip to content

Commit

Permalink
fix #129
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Feb 23, 2014
1 parent 774161b commit 79f6193
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,14 @@ function extend (options) {
* extension option, but only as an instance option.
*/
function inheritOptions (child, parent, topLevel) {
child = child || makeHash()
child = child || {}
if (!parent) return child
for (var key in parent) {
if (key === 'el' || key === 'methods') continue
var val = child[key],
parentVal = parent[key],
type = utils.typeOf(val)
type = utils.typeOf(val),
parentType = utils.typeOf(parentVal)
if (topLevel && type === 'Function' && parentVal) {
// merge hook functions into an array
child[key] = [val]
Expand All @@ -169,9 +170,9 @@ function inheritOptions (child, parent, topLevel) {
} else {
child[key].push(parentVal)
}
} else if (topLevel && type === 'Object') {
} else if (topLevel && (type === 'Object' || parentType === 'Object')) {
// merge toplevel object options
inheritOptions(val, parentVal)
child[key] = inheritOptions(val, parentVal)
} else if (val === undefined) {
// inherit if child doesn't override
child[key] = parentVal
Expand Down
14 changes: 10 additions & 4 deletions test/unit/specs/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,17 @@ describe('UNIT: API', function () {
})

it('should allow subclasses to attach private assets', function () {
var testId = 'sub-private'
var Sub = Vue.extend({})
Sub.component('test', {})
assert.strictEqual(Sub.options.components.test.super, Vue)
Sub.partial('test', '123')
assert.ok(Sub.options.partials.test instanceof window.DocumentFragment)
Sub.component(testId, {})
assert.strictEqual(Sub.options.components[testId].super, Vue)
Sub.partial(testId, '123')
assert.ok(Sub.options.partials[testId] instanceof window.DocumentFragment)

var Sub2 = Vue.extend({})
Sub2.component(testId, {})
assert.notStrictEqual(Sub.options.components[testId], Sub2.options.components[testId])
assert.notOk(Vue.options.components[testId])
})

it('should allow subclasses to use plugins', function () {
Expand Down

0 comments on commit 79f6193

Please sign in to comment.