File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed
Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -110,13 +110,24 @@ export class ReplicaCache {
110110
111111 _isClosed = false ;
112112
113+ _onFireCacheUpdatedsWrapper = ( cb : ( ) => void ) => cb ( ) ;
114+
113115 /**
114116 * Create a new ReplicaCache.
115117 * @param timeToLive - The number of milliseconds a cached document is considered valid for.
118+ * @param onCacheUpdatedWrapper - A function which wraps the firing of all callbacks. Useful for libraries with batching abstractions.
116119 */
117- constructor ( replica : IReplica , timeToLive ?: number ) {
120+ constructor (
121+ replica : IReplica ,
122+ timeToLive ?: number ,
123+ onCacheUpdatedWrapper ?: ( cb : ( ) => void ) => void ,
124+ ) {
118125 this . _replica = replica ;
119126 this . _timeToLive = timeToLive || 1000 ;
127+
128+ if ( onCacheUpdatedWrapper ) {
129+ this . _onFireCacheUpdatedsWrapper = onCacheUpdatedWrapper ;
130+ }
120131 }
121132
122133 async close ( ) {
@@ -442,8 +453,10 @@ export class ReplicaCache {
442453 _fireOnCacheUpdateds ( entry : string ) {
443454 this . version ++ ;
444455
445- this . _onCacheUpdatedCallbacks . forEach ( ( cb ) => {
446- cb ( entry ) ;
456+ this . _onFireCacheUpdatedsWrapper ( ( ) => {
457+ this . _onCacheUpdatedCallbacks . forEach ( ( cb ) => {
458+ cb ( entry ) ;
459+ } ) ;
447460 } ) ;
448461 }
449462
You can’t perform that action at this time.
0 commit comments