How to use the @graffy/stream function in @graffy/stream

To help you get started, we’ve selected a few @graffy/stream examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github usegraffy / graffy / src / fill / subscribe.js View on Github external
export default function subscribe(store, originalQuery, raw) {
  let push, end;
  let upstream;
  let query = [];
  let data = [];
  let payload = [];

  resubscribe(originalQuery);

  return makeStream((streamPush, streamEnd) => {
    push = v => {
      // console.log('Push', debug(v));
      streamPush(v);
    };
    end = streamEnd;
    return unsubscribe;
  });

  async function resubscribe(unknown, _extraneous) {
    try {
      const changed = add(query, unknown);
      // console.log('Resubscribe');
      if (!changed) return;

      if (upstream) upstream.return(); // Close the existing stream.
      upstream = store.call('watch', query, { skipFill: true });
github usegraffy / graffy / src / core / shift.js View on Github external
pushRemaining = push;
      });

      for await (const value of next(nextPayload)) {
        const unwrappedValue = unwrap(value, path);
        const remainingValue = remove(value, path);
        if (remainingValue) pushRemaining(remainingValue);
        if (unwrappedValue) yield unwrappedValue;
      }
    };

    const unwrappedStream = fn(unwrappedPayload, options, shiftedNext);

    // We expect next() to be called before the first value is yielded.
    const firstValue = await (await unwrappedStream.next()).value;
    const resultStream = makeStream(push => {
      push(wrap(firstValue, path));
      mapStream(unwrappedStream, value => {
        push(wrap(value, path));
      });
      return () => unwrappedStream.return();
    });

    if (!nextCalled && remainingPayload.length) {
      remainingNextStream = next(remainingPayload);
    }

    yield* remainingNextStream
      ? mergeStreams(resultStream, remainingNextStream)
      : resultStream;
  };
}
github usegraffy / graffy / src / core / shift.js View on Github external
const shiftedNext = async function*(unwrappedNextPayload) {
      nextCalled = true;
      const nextPayload = wrap(unwrappedNextPayload, path);
      if (remainingPayload.length) merge(nextPayload, remainingPayload);

      let pushRemaining;
      remainingNextStream = makeStream(push => {
        pushRemaining = push;
      });

      for await (const value of next(nextPayload)) {
        const unwrappedValue = unwrap(value, path);
        const remainingValue = remove(value, path);
        if (remainingValue) pushRemaining(remainingValue);
        if (unwrappedValue) yield unwrappedValue;
      }
    };

@graffy/stream

Utility for creating AsyncIterables (streams) from any callback-based

Apache-2.0
Latest version published 6 months ago

Package Health Score

62 / 100
Full package analysis

Popular @graffy/stream functions