@@ -26,29 +26,20 @@ function subscribeToRefs ({
26
26
delete subs [ refKey ]
27
27
} )
28
28
if ( ! refKeys . length ) return resolve ( )
29
- // TODO check if no ref is missing
30
29
// TODO max depth param, default to 1?
31
30
if ( ++ depth > 3 ) throw new Error ( 'more than 5 nested refs' )
32
31
33
32
refKeys . forEach ( refKey => {
34
- // check if already bound to the same ref -> skip
35
- // TODO reuse if already bound?
36
33
const sub = subs [ refKey ]
37
34
const ref = refs [ refKey ]
38
35
36
+ // unsubscribe if bound to a different ref
39
37
if ( sub ) {
40
38
if ( sub . path !== ref . path ) sub . unsub ( )
41
39
// if has already be bound and as we always walk the objects, it will work
42
40
else return
43
41
}
44
42
45
- // maybe wrap the unbind function to call unbind on every child
46
- // const [innerObj, innerKey] = deepGetSplit(target[key], refKey)
47
- // if (!innerObj) {
48
- // console.log('=== ERROR ===')
49
- // console.log(data, refKey, key, innerObj, innerKey)
50
- // console.log('===')
51
- // }
52
43
subs [ refKey ] = {
53
44
unsub : subscribeToDocument ( {
54
45
ref,
@@ -69,8 +60,7 @@ function bindCollection ({
69
60
resolve,
70
61
reject
71
62
} ) {
72
- // TODO wait to get all data
73
- // XXX support pathes? nested.obj.list
63
+ // TODO support pathes? nested.obj.list (walkSet)
74
64
const array = vm [ key ] = [ ]
75
65
const originalResolve = resolve
76
66
let isResolved
@@ -137,7 +127,6 @@ function bindCollection ({
137
127
resolve = ( { id } ) => {
138
128
if ( id in validDocs ) {
139
129
if ( ++ count >= expectedItems ) {
140
- // TODO use array instead?
141
130
originalResolve ( vm [ key ] )
142
131
// reset resolve to noop
143
132
resolve = _ => { }
@@ -227,7 +216,6 @@ function bindDocument ({
227
216
}
228
217
} , reject )
229
218
230
- // TODO return a custom unbind function that unbind all refs
231
219
return ( ) => {
232
220
unbind ( )
233
221
unsubscribeAll ( subs )
0 commit comments