Skip to content

Commit

Permalink
Support delivering initial cache.watch results immediately, if reques…
Browse files Browse the repository at this point in the history
…ted.

I needed this functionality for some tests of cache.modify, but I think I
can expand it into a version of cache.watch that returns an async iterator
if you do not supply a callback.
  • Loading branch information
benjamn committed Feb 7, 2020
1 parent 689846e commit fcf2e2a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/cache/core/types/Cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export namespace Cache {
}

export interface WatchOptions extends ReadOptions {
immediate?: boolean;
callback: WatchCallback;
}

Expand Down
4 changes: 3 additions & 1 deletion src/cache/inmemory/inMemoryCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {

public watch(watch: Cache.WatchOptions): () => void {
this.watches.add(watch);

if (watch.immediate) {
this.maybeBroadcastWatch(watch);
}
return () => {
this.watches.delete(watch);
};
Expand Down

0 comments on commit fcf2e2a

Please sign in to comment.