Skip to content

Commit 560bcf0

Browse files
committed
fix(refs): updated collection should not contain DocumentReference
it's important to always put plain by extracting the refs from documents before setting the information in the array or document
1 parent ef9aeb2 commit 560bcf0

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function subscribeToRefs ({
3131
const ref = refs[refKey]
3232

3333
// documents are fully replaced so it's necessary to bind things again
34+
// TODO it would be nice to prevent unnecessary unbind
3435
if (sub) sub.unbind()
3536

3637
// maybe wrap the unbind function to call unbind on every child
@@ -91,8 +92,8 @@ function bindCollection ({
9192
arraySubs.splice(newIndex, 0, subs)
9293
array.splice(oldIndex, 1)
9394
const snapshot = createSnapshot(doc)
94-
array.splice(newIndex, 0, snapshot)
9595
const [data, refs] = extractRefs(snapshot)
96+
array.splice(newIndex, 0, data)
9697
subscribeToRefs({
9798
data,
9899
refs,

test/refs-collections.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,15 @@ test('updates when modifying an item', async () => {
137137
{ ref: { isB: true }}
138138
])
139139
})
140+
141+
test('removes the DocumentReference when modifying an item', async () => {
142+
await vm.$bind('items', collection)
143+
await first.update({ newThing: true })
144+
145+
expect(typeof vm.items[0].ref).toBe('string')
146+
await delay(5)
147+
expect(vm.items[0]).toEqual({
148+
ref: { isA: true },
149+
newThing: true
150+
})
151+
})

test/refs-documents.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,5 +386,4 @@ test('properly updates a documen with refs', async () => {
386386
newThing: true,
387387
a: { isA: true }
388388
})
389-
390389
})

0 commit comments

Comments
 (0)