@@ -107,6 +107,8 @@ export function getDecoderStateCallbacks<T extends Schema>(decoder: Decoder<T>):
107
107
let currentOnAddCallback : Function | undefined ;
108
108
109
109
decoder . triggerChanges = function ( allChanges : DataChange [ ] ) {
110
+ // console.log("ALL CHANGES =>", allChanges);
111
+
110
112
const uniqueRefIds = new Set < number > ( ) ;
111
113
112
114
for ( let i = 0 , l = allChanges . length ; i < l ; i ++ ) {
@@ -290,7 +292,9 @@ export function getDecoderStateCallbacks<T extends Schema>(decoder: Decoder<T>):
290
292
const instance = context . instance ?. [ prop ] ;
291
293
const onInstanceAvailable : OnInstanceAvailableCallback = (
292
294
( callback : ( ref : Ref , existing : boolean ) => void ) => {
295
+ console . log ( "onInstanceAvailable!!" ) ;
293
296
const unbind = $ ( context . instance ) . listen ( prop , ( value , _ ) => {
297
+ console . log ( "prop changed!" , prop ) ;
294
298
callback ( value , false ) ;
295
299
296
300
// FIXME: by "unbinding" the callback here,
@@ -306,6 +310,7 @@ export function getDecoderStateCallbacks<T extends Schema>(decoder: Decoder<T>):
306
310
}
307
311
}
308
312
) ;
313
+
309
314
return getProxy ( metadataField . type , {
310
315
// make sure refId is available, otherwise need to wait for the instance to be available.
311
316
instance : ( $root . refIds . get ( instance ) && instance ) ,
@@ -344,10 +349,12 @@ export function getDecoderStateCallbacks<T extends Schema>(decoder: Decoder<T>):
344
349
} ;
345
350
346
351
const onRemove = function ( ref : Ref , callback : ( value : any , key : any ) => void ) {
352
+ console . log ( "REGISTER ON REMOVE ON" , $root . refIds . get ( ref ) ) ;
347
353
return $root . addCallback ( $root . refIds . get ( ref ) , OPERATION . DELETE , callback ) ;
348
354
} ;
349
355
350
356
const onChange = function ( ref : Ref , callback : ( value : any , key : any ) => void ) {
357
+ console . log ( "REGISTER ON CHANGE ON" , $root . refIds . get ( ref ) ) ;
351
358
return $root . addCallback ( $root . refIds . get ( ref ) , OPERATION . REPLACE , callback ) ;
352
359
} ;
353
360
@@ -373,7 +380,10 @@ export function getDecoderStateCallbacks<T extends Schema>(decoder: Decoder<T>):
373
380
}
374
381
} ,
375
382
onRemove : function ( callback : ( value , key ) => void ) {
376
- if ( context . onInstanceAvailable ) {
383
+ if ( context . instance ) {
384
+ return onRemove ( context . instance , callback ) ;
385
+
386
+ } else if ( context . onInstanceAvailable ) {
377
387
// collection instance not received yet
378
388
let detachCallback = ( ) => { } ;
379
389
@@ -382,13 +392,13 @@ export function getDecoderStateCallbacks<T extends Schema>(decoder: Decoder<T>):
382
392
} ) ;
383
393
384
394
return ( ) => detachCallback ( ) ;
385
-
386
- } else if ( context . instance ) {
387
- return onRemove ( context . instance , callback ) ;
388
395
}
389
396
} ,
390
397
onChange : function ( callback : ( value , key ) => void ) {
391
- if ( context . onInstanceAvailable ) {
398
+ if ( context . instance ) {
399
+ return onChange ( context . instance , callback ) ;
400
+
401
+ } else if ( context . onInstanceAvailable ) {
392
402
// collection instance not received yet
393
403
let detachCallback = ( ) => { } ;
394
404
@@ -397,9 +407,6 @@ export function getDecoderStateCallbacks<T extends Schema>(decoder: Decoder<T>):
397
407
} ) ;
398
408
399
409
return ( ) => detachCallback ( ) ;
400
-
401
- } else if ( context . instance ) {
402
- return onChange ( context . instance , callback ) ;
403
410
}
404
411
} ,
405
412
} , {
0 commit comments