Skip to content

Commit

Permalink
refactor: rename callUnbinds => unsubscribeAll
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Dec 28, 2017
1 parent 86a7f84 commit 31f81a5
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createSnapshot, extractRefs, callOnceWithArg, walkGet, walkSet } from './utils'

function callUnbinds (subs) {
function unsubscribeAll (subs) {
for (const sub in subs) {
subs[sub].unbind()
subs[sub].unsub()
}
}

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

if (sub) {
if (sub.path !== ref.path) sub.unbind()
if (sub.path !== ref.path) sub.unsub()
// if has already be bound and as we always walk the objects, it will work
else return
}
Expand All @@ -50,7 +50,7 @@ function subscribeToRefs ({
// console.log('===')
// }
subs[refKey] = {
unbind: subscribeToDocument({
unsub: subscribeToDocument({
ref,
target,
path: `${path}.${refKey}`,
Expand Down Expand Up @@ -115,7 +115,7 @@ function bindCollection ({
},
removed: ({ oldIndex }) => {
array.splice(oldIndex, 1)
callUnbinds(arraySubs.splice(oldIndex, 1)[0])
unsubscribeAll(arraySubs.splice(oldIndex, 1)[0])
}
}

Expand Down Expand Up @@ -156,7 +156,7 @@ function bindCollection ({

return () => {
unbind()
arraySubs.forEach(callUnbinds)
arraySubs.forEach(unsubscribeAll)
}
}

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

return () => {
unbind()
callUnbinds(subs)
unsubscribeAll(subs)
}
}

Expand Down Expand Up @@ -237,10 +237,7 @@ function bindDocument ({
// TODO return a custom unbind function that unbind all refs
return () => {
unbind()
for (const subKey in subs) {
const sub = subs[subKey]
sub.unbind()
}
unsubscribeAll(subs)
}
}

Expand Down

0 comments on commit 31f81a5

Please sign in to comment.