Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to extend a component #2701

Merged
merged 1 commit into from
Apr 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/util/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ export function mergeOptions (parent, child, vm) {
}
var options = {}
var key
if (child.extends) {
parent = mergeOptions(parent, child.extends, vm)
}
if (child.mixins) {
for (var i = 0, l = child.mixins.length; i < l; i++) {
parent = mergeOptions(parent, child.mixins[i], vm)
Expand Down
14 changes: 14 additions & 0 deletions test/unit/specs/util/options_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,20 @@ describe('Util - Option merging', function () {
expect(Object.getOwnPropertyDescriptor(data, 'b').get).toBeTruthy()
})

it('extends', function () {
var f1 = function () {}
var f2 = function () {}
var f3 = function () {}
var componentA = { template: 'foo', methods: { f1: f1, f2: function () {} } }
var componentB = { extends: componentA, methods: { f2: f2 } }
var componentC = { extends: componentB, template: 'bar', methods: { f3: f3 } }
var res = merge({}, componentC)
expect(res.template).toBe('bar')
expect(res.methods.f1).toBe(f1)
expect(res.methods.f2).toBe(f2)
expect(res.methods.f3).toBe(f3)
})

it('mixins', function () {
var a = {}
var b = {}
Expand Down