Skip to content

Commit

Permalink
Add experimental buffer fix for edge cases in Svelte/Preact
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Sep 30, 2020
1 parent f87d4db commit 326d51d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions exchanges/graphcache/src/cacheExchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import {

import {
filter,
combine,
scan,
map,
merge,
pipe,
share,
fromPromise,
fromArray,
buffer,
take,
mergeMap,
concat,
Expand Down Expand Up @@ -249,10 +250,15 @@ export const cacheExchange = (opts?: CacheExchangeOpts): Exchange => ({
// If no hydration takes place we replace this stream with an empty one
const bufferedOps$ = hydration
? pipe(
sharedOps$,
buffer(fromPromise(hydration)),
take(1),
mergeMap(fromArray)
combine(
pipe(
sharedOps$,
scan((acc: Operation[], x) => (acc.push(x), acc), [])
),
fromPromise(hydration)
),
mergeMap(zip => fromArray(zip[0])),
take(1)
)
: (empty as Source<Operation>);

Expand Down

0 comments on commit 326d51d

Please sign in to comment.