Skip to content

Commit 676b4d0

Browse files
committed
Merge pull request #118 from bpierre/plugin-options
Implements plugin parameters
2 parents 97c1a81 + aaf0b48 commit 676b4d0

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

src/main.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,15 @@ ViewModel.use = function (plugin) {
6666
return utils.warn('Cannot find plugin: ' + plugin)
6767
}
6868
}
69-
if (typeof plugin === 'function') {
70-
plugin(ViewModel)
71-
} else if (plugin.install) {
72-
plugin.install(ViewModel)
69+
70+
// additional parameters
71+
var args = [].slice.call(arguments, 1)
72+
args.unshift(ViewModel)
73+
74+
if (typeof plugin.install === 'function') {
75+
plugin.install.apply(plugin, args)
76+
} else {
77+
plugin.apply(null, args)
7378
}
7479
}
7580

test/unit/specs/api.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('UNIT: API', function () {
6161
assert.ok(called)
6262
})
6363

64-
it('should install a plugin if its a function itself', function () {
64+
it('should install a plugin if it’s a function itself', function () {
6565
var called = false
6666
Vue.use(function (vue) {
6767
called = true
@@ -70,6 +70,36 @@ describe('UNIT: API', function () {
7070
assert.ok(called)
7171
})
7272

73+
it('should pass any additional parameter', function () {
74+
var param1 = 'a',
75+
param2 = { b: 'c' }
76+
77+
Vue.use(function (vue, p1, p2) {
78+
assert.strictEqual(p1, param1)
79+
assert.strictEqual(p2, param2)
80+
}, param1, param2)
81+
82+
Vue.use({
83+
install: function (vue, p1, p2) {
84+
assert.strictEqual(p1, param1)
85+
assert.strictEqual(p2, param2)
86+
}
87+
}, param1, param2)
88+
})
89+
90+
it('should properly set the value of this', function () {
91+
var plugin = {
92+
install: function () {
93+
assert.strictEqual(this, plugin)
94+
}
95+
}
96+
Vue.use(plugin)
97+
98+
Vue.use(function () {
99+
assert.strictEqual(this, global)
100+
})
101+
})
102+
73103
})
74104

75105
describe('filter()', function () {

test/unit/utils/prepare.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@ Vue.config({silent:true})
4242
var testDiv = document.createElement('div')
4343
testDiv.id = 'test'
4444
testDiv.style.display = 'none'
45-
document.body.appendChild(testDiv)
45+
document.body.appendChild(testDiv)
46+
47+
var global = this

0 commit comments

Comments
 (0)