Skip to content

Commit 31f81a5

Browse files
committed
refactor: rename callUnbinds => unsubscribeAll
1 parent 86a7f84 commit 31f81a5

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/index.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { createSnapshot, extractRefs, callOnceWithArg, walkGet, walkSet } from './utils'
22

3-
function callUnbinds (subs) {
3+
function unsubscribeAll (subs) {
44
for (const sub in subs) {
5-
subs[sub].unbind()
5+
subs[sub].unsub()
66
}
77
}
88

@@ -22,7 +22,7 @@ function subscribeToRefs ({
2222
const missingKeys = Object.keys(subs).filter(refKey => refKeys.indexOf(refKey) < 0)
2323
// unbind keys that are no longer there
2424
missingKeys.forEach(refKey => {
25-
subs[refKey].unbind()
25+
subs[refKey].unsub()
2626
delete subs[refKey]
2727
})
2828
if (!refKeys.length) return resolve()
@@ -37,7 +37,7 @@ function subscribeToRefs ({
3737
const ref = refs[refKey]
3838

3939
if (sub) {
40-
if (sub.path !== ref.path) sub.unbind()
40+
if (sub.path !== ref.path) sub.unsub()
4141
// if has already be bound and as we always walk the objects, it will work
4242
else return
4343
}
@@ -50,7 +50,7 @@ function subscribeToRefs ({
5050
// console.log('===')
5151
// }
5252
subs[refKey] = {
53-
unbind: subscribeToDocument({
53+
unsub: subscribeToDocument({
5454
ref,
5555
target,
5656
path: `${path}.${refKey}`,
@@ -115,7 +115,7 @@ function bindCollection ({
115115
},
116116
removed: ({ oldIndex }) => {
117117
array.splice(oldIndex, 1)
118-
callUnbinds(arraySubs.splice(oldIndex, 1)[0])
118+
unsubscribeAll(arraySubs.splice(oldIndex, 1)[0])
119119
}
120120
}
121121

@@ -156,7 +156,7 @@ function bindCollection ({
156156

157157
return () => {
158158
unbind()
159-
arraySubs.forEach(callUnbinds)
159+
arraySubs.forEach(unsubscribeAll)
160160
}
161161
}
162162

@@ -201,7 +201,7 @@ function subscribeToDocument ({ ref, target, path, depth, resolve }) {
201201

202202
return () => {
203203
unbind()
204-
callUnbinds(subs)
204+
unsubscribeAll(subs)
205205
}
206206
}
207207

@@ -237,10 +237,7 @@ function bindDocument ({
237237
// TODO return a custom unbind function that unbind all refs
238238
return () => {
239239
unbind()
240-
for (const subKey in subs) {
241-
const sub = subs[subKey]
242-
sub.unbind()
243-
}
240+
unsubscribeAll(subs)
244241
}
245242
}
246243

0 commit comments

Comments
 (0)