Skip to content

Commit 75c3e73

Browse files
committed
fix: pass a default options to bind*
1 parent 3907c6d commit 75c3e73

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

packages/@posva/vuefire-core/src/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ function subscribeToRefs({ subs, refs, target, path, data, depth, ops, resolve }
5959
})
6060
}
6161

62-
export function bindCollection({ vm, key, collection, ops, resolve, reject }, options) {
62+
export function bindCollection(
63+
{ vm, key, collection, ops, resolve, reject },
64+
options = { maxRefDepth: 2 }
65+
) {
6366
// TODO support pathes? nested.obj.list (walkSet)
6467
// NOTE use ops object
6568
const array = ops.set(vm, key, [])
@@ -170,7 +173,7 @@ export function bindCollection({ vm, key, collection, ops, resolve, reject }, op
170173

171174
function updateDataFromDocumentSnapshot(
172175
{ snapshot, target, path, subs, ops, depth = 0, resolve },
173-
options
176+
options = { maxRefDepth: 2 }
174177
) {
175178
const [data, refs] = extractRefs(snapshot, walkGet(target, path))
176179
// NOTE use ops

packages/@posva/vuefire-core/test/collection.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,14 @@ describe('collections', () => {
115115
).rejects.toThrow()
116116
collection.onSnapshot.mockRestore()
117117
})
118+
119+
it('resolves when the collection is populated', async () => {
120+
await collection.add({ foo: 'foo' })
121+
await collection.add({ foo: 'foo' })
122+
const promise = new Promise((resolve, reject) => {
123+
bindCollection({ vm, collection, key: 'items', resolve, reject, ops })
124+
})
125+
await promise
126+
expect(vm.items).toEqual([{ foo: 'foo' }, { foo: 'foo' }])
127+
})
118128
})

packages/@posva/vuefire-core/test/document.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,13 @@ describe('documents', () => {
8080
).rejects.toThrow()
8181
document.onSnapshot.mockRestore()
8282
})
83+
84+
it('resolves when the document is set', async () => {
85+
await document.update({ foo: 'foo' })
86+
const promise = new Promise((resolve, reject) => {
87+
bindDocument({ vm, document, key: 'item', resolve, reject, ops })
88+
})
89+
await promise
90+
expect(vm.item).toEqual({ foo: 'foo' })
91+
})
8392
})

0 commit comments

Comments
 (0)