@@ -164,7 +164,7 @@ class Nursery implements SyncPush<State> {
164164class Heap implements SyncPush < Revision < State > > {
165165 constructor (
166166 public store : Map < string , Revision < State > > = new Map ( ) ,
167- public subscribers : Map < string , Set < ( revision : Revision < State > ) => void > > =
167+ public subscribers : Map < string , Set < ( revision ? : Revision < State > ) => void > > =
168168 new Map ( ) ,
169169 ) {
170170 }
@@ -191,14 +191,17 @@ class Heap implements SyncPush<Revision<State>> {
191191 // Notify all the subscribers
192192 for ( const key of updated ) {
193193 for ( const subscriber of this . subscribers . get ( key ) ?? [ ] ) {
194- subscriber ( this . store . get ( key ) ! ) ;
194+ subscriber ( this . store . get ( key ) ) ;
195195 }
196196 }
197197
198198 return { ok : { } } ;
199199 }
200200
201- subscribe ( entry : FactAddress , subscriber : ( value : Revision < State > ) => void ) {
201+ subscribe (
202+ entry : FactAddress ,
203+ subscriber : ( value ?: Revision < State > ) => void ,
204+ ) {
202205 const key = toKey ( entry ) ;
203206 let subscribers = this . subscribers . get ( key ) ;
204207 if ( ! subscribers ) {
@@ -211,7 +214,7 @@ class Heap implements SyncPush<Revision<State>> {
211214
212215 unsubscribe (
213216 entry : FactAddress ,
214- subscriber : ( value : Revision < State > ) => void ,
217+ subscriber : ( value ? : Revision < State > ) => void ,
215218 ) {
216219 const key = toKey ( entry ) ;
217220 const subscribers = this . subscribers . get ( key ) ;
@@ -605,12 +608,12 @@ export class Replica {
605608 }
606609 }
607610
608- subscribe ( entry : FactAddress , subscriber : ( value : Revision < State > ) => void ) {
611+ subscribe ( entry : FactAddress , subscriber : ( value ? : Revision < State > ) => void ) {
609612 this . heap . subscribe ( entry , subscriber ) ;
610613 }
611614 unsubscribe (
612615 entry : FactAddress ,
613- subscriber : ( value : Revision < State > ) => void ,
616+ subscriber : ( value ? : Revision < State > ) => void ,
614617 ) {
615618 this . heap . unsubscribe ( entry , subscriber ) ;
616619 }
@@ -765,8 +768,13 @@ export class Provider implements StorageProvider {
765768 const of = Provider . toEntity ( entityId ) ;
766769 const { workspace } = this ;
767770 const address = { the, of } ;
768- const subscriber = ( revision : Revision < State > ) => {
769- callback ( revision . is as unknown as StorageValue < T > ) ;
771+ const subscriber = ( revision ?: Revision < State > ) => {
772+ if ( revision ) {
773+ // ⚠️ We may not have a value because fact was retracted or
774+ // (less likely) deleted alltogether. I assume we still need to
775+ // call callback but it is not clear what should we pass into it.
776+ callback ( revision ?. is as unknown as StorageValue < T > ) ;
777+ }
770778 } ;
771779
772780 workspace . subscribe ( address , subscriber ) ;
0 commit comments