Skip to content

Commit

Permalink
fix(refs): updated collection should not contain DocumentReference
Browse files Browse the repository at this point in the history
it's important to always put plain by extracting the refs from documents before setting the
information in the array or document
  • Loading branch information
posva committed Dec 28, 2017
1 parent ef9aeb2 commit 560bcf0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function subscribeToRefs ({
const ref = refs[refKey]

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

// maybe wrap the unbind function to call unbind on every child
Expand Down Expand Up @@ -91,8 +92,8 @@ function bindCollection ({
arraySubs.splice(newIndex, 0, subs)
array.splice(oldIndex, 1)
const snapshot = createSnapshot(doc)
array.splice(newIndex, 0, snapshot)
const [data, refs] = extractRefs(snapshot)
array.splice(newIndex, 0, data)
subscribeToRefs({
data,
refs,
Expand Down
12 changes: 12 additions & 0 deletions test/refs-collections.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,15 @@ test('updates when modifying an item', async () => {
{ ref: { isB: true }}
])
})

test('removes the DocumentReference when modifying an item', async () => {
await vm.$bind('items', collection)
await first.update({ newThing: true })

expect(typeof vm.items[0].ref).toBe('string')
await delay(5)
expect(vm.items[0]).toEqual({
ref: { isA: true },
newThing: true
})
})
1 change: 0 additions & 1 deletion test/refs-documents.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,5 +386,4 @@ test('properly updates a documen with refs', async () => {
newThing: true,
a: { isA: true }
})

})

0 comments on commit 560bcf0

Please sign in to comment.