Skip to content

Commit

Permalink
feat(refs): unbinds refs when removing from collection
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Dec 26, 2017
1 parent 778158e commit 7abe7d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ function bindCollection ({
},
removed: ({ oldIndex }) => {
array.splice(oldIndex, 1)
// TODO remove listeners of nested refs
const subs = arraySubs.splice(oldIndex, 1)[0]
for (const subKey in subs) {
subs[subKey].unbind()
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions test/refs-collections.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,17 @@ test('unbinds nested refs when the collection is unbound', async () => {
expect(spyA).toHaveBeenCalledTimes(0)

vm.$unbind('items')
expect(spyA).toHaveBeenCalledTimes(1)

spyA.mockRestore()
})

test('unbinds refs when items are removed', async () => {
const spyA = spyUnbind(a)
await vm.$bind('items', collection)
expect(spyA).toHaveBeenCalledTimes(0)

await collection.doc(a.id).delete()
expect(spyA).toHaveBeenCalledTimes(1)

spyA.mockRestore()
Expand Down

0 comments on commit 7abe7d6

Please sign in to comment.