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 d540b0f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 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)),
combine(
pipe(
sharedOps$,
scan((acc: Operation[], x) => (acc.push(x), acc), [])
),
fromPromise(hydration)
),
take(1),
mergeMap(fromArray)
mergeMap(zip => fromArray(zip[0]))
)
: (empty as Source<Operation>);

Expand Down

0 comments on commit d540b0f

Please sign in to comment.