1
1
import { createSnapshot , extractRefs , callOnceWithArg , walkGet , walkSet } from './utils'
2
2
3
- function callUnbinds ( subs ) {
3
+ function unsubscribeAll ( subs ) {
4
4
for ( const sub in subs ) {
5
- subs [ sub ] . unbind ( )
5
+ subs [ sub ] . unsub ( )
6
6
}
7
7
}
8
8
@@ -22,7 +22,7 @@ function subscribeToRefs ({
22
22
const missingKeys = Object . keys ( subs ) . filter ( refKey => refKeys . indexOf ( refKey ) < 0 )
23
23
// unbind keys that are no longer there
24
24
missingKeys . forEach ( refKey => {
25
- subs [ refKey ] . unbind ( )
25
+ subs [ refKey ] . unsub ( )
26
26
delete subs [ refKey ]
27
27
} )
28
28
if ( ! refKeys . length ) return resolve ( )
@@ -37,7 +37,7 @@ function subscribeToRefs ({
37
37
const ref = refs [ refKey ]
38
38
39
39
if ( sub ) {
40
- if ( sub . path !== ref . path ) sub . unbind ( )
40
+ if ( sub . path !== ref . path ) sub . unsub ( )
41
41
// if has already be bound and as we always walk the objects, it will work
42
42
else return
43
43
}
@@ -50,7 +50,7 @@ function subscribeToRefs ({
50
50
// console.log('===')
51
51
// }
52
52
subs [ refKey ] = {
53
- unbind : subscribeToDocument ( {
53
+ unsub : subscribeToDocument ( {
54
54
ref,
55
55
target,
56
56
path : `${ path } .${ refKey } ` ,
@@ -115,7 +115,7 @@ function bindCollection ({
115
115
} ,
116
116
removed : ( { oldIndex } ) => {
117
117
array . splice ( oldIndex , 1 )
118
- callUnbinds ( arraySubs . splice ( oldIndex , 1 ) [ 0 ] )
118
+ unsubscribeAll ( arraySubs . splice ( oldIndex , 1 ) [ 0 ] )
119
119
}
120
120
}
121
121
@@ -156,7 +156,7 @@ function bindCollection ({
156
156
157
157
return ( ) => {
158
158
unbind ( )
159
- arraySubs . forEach ( callUnbinds )
159
+ arraySubs . forEach ( unsubscribeAll )
160
160
}
161
161
}
162
162
@@ -201,7 +201,7 @@ function subscribeToDocument ({ ref, target, path, depth, resolve }) {
201
201
202
202
return ( ) => {
203
203
unbind ( )
204
- callUnbinds ( subs )
204
+ unsubscribeAll ( subs )
205
205
}
206
206
}
207
207
@@ -237,10 +237,7 @@ function bindDocument ({
237
237
// TODO return a custom unbind function that unbind all refs
238
238
return ( ) => {
239
239
unbind ( )
240
- for ( const subKey in subs ) {
241
- const sub = subs [ subKey ]
242
- sub . unbind ( )
243
- }
240
+ unsubscribeAll ( subs )
244
241
}
245
242
}
246
243
0 commit comments