Skip to content

Commit 6989fb5

Browse files
committed
feat(option): support merging like data
1 parent 8439c72 commit 6989fb5

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

src/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,19 @@ function bind ({ vm, key, ref }) {
146146

147147
function install (Vue, options) {
148148
const strategies = Vue.config.optionMergeStrategies
149-
strategies.firestore = strategies.methods
149+
strategies.firestore = strategies.provide
150150

151151
Vue.mixin({
152152
created () {
153153
const { firestore } = this.$options
154154
this._firestoreUnbinds = Object.create(null)
155155
this.$firestoreRefs = Object.create(null)
156156
if (!firestore) return
157-
Object.keys(firestore).forEach(key => {
158-
this.$bind(key, firestore[key])
157+
const options = typeof firestore === 'function'
158+
? firestore.call(this, this)
159+
: firestore
160+
Object.keys(options).forEach(key => {
161+
this.$bind(key, options[key])
159162
})
160163
},
161164

test/merging.spec.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66

77
Vue.use(Vuefire)
88

9-
let mWithObjA, mWithObjB
9+
let mWithObjA, mWithObjB, mWithFn
1010
beforeEach(async () => {
1111
mWithObjA = {
1212
firestore: {
@@ -21,6 +21,15 @@ beforeEach(async () => {
2121
c: db.collection(4)
2222
}
2323
}
24+
25+
mWithFn = {
26+
firestore () {
27+
return {
28+
a: db.collection(5),
29+
c: db.collection(6)
30+
}
31+
}
32+
}
2433
})
2534

2635
test('should merge properties', () => {
@@ -35,4 +44,25 @@ test('should merge properties', () => {
3544
})
3645
})
3746

38-
test('TODO: should merge two functions')
47+
test('supports function syntax', () => {
48+
const vm = new Vue({
49+
mixins: [mWithFn],
50+
render: h => h('p', 'foo')
51+
})
52+
expect(vm.$firestoreRefs).toEqual({
53+
a: db.collection(5),
54+
c: db.collection(6)
55+
})
56+
})
57+
58+
test('should merge two functions', () => {
59+
const vm = new Vue({
60+
mixins: [mWithObjA, mWithObjB, mWithFn],
61+
render: h => h('p', 'foo')
62+
})
63+
expect(vm.$firestoreRefs).toEqual({
64+
a: db.collection(5),
65+
b: db.collection(2),
66+
c: db.collection(6)
67+
})
68+
})

0 commit comments

Comments
 (0)