Skip to content

Commit 7abe7d6

Browse files
committed
feat(refs): unbinds refs when removing from collection
1 parent 778158e commit 7abe7d6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ function bindCollection ({
9595
},
9696
removed: ({ oldIndex }) => {
9797
array.splice(oldIndex, 1)
98-
// TODO remove listeners of nested refs
98+
const subs = arraySubs.splice(oldIndex, 1)[0]
99+
for (const subKey in subs) {
100+
subs[subKey].unbind()
101+
}
99102
}
100103
}
101104

test/refs-collections.spec.js

+10
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,17 @@ test('unbinds nested refs when the collection is unbound', async () => {
9898
expect(spyA).toHaveBeenCalledTimes(0)
9999

100100
vm.$unbind('items')
101+
expect(spyA).toHaveBeenCalledTimes(1)
102+
103+
spyA.mockRestore()
104+
})
105+
106+
test('unbinds refs when items are removed', async () => {
107+
const spyA = spyUnbind(a)
108+
await vm.$bind('items', collection)
109+
expect(spyA).toHaveBeenCalledTimes(0)
101110

111+
await collection.doc(a.id).delete()
102112
expect(spyA).toHaveBeenCalledTimes(1)
103113

104114
spyA.mockRestore()

0 commit comments

Comments
 (0)