How to use the @graffy/common.unwrap function in @graffy/common

To help you get started, we’ve selected a few @graffy/common 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 / example / mockVisitorList.js View on Github external
function simulateLeave() {
  let delId;
  do {
    delId = Math.floor(Math.random() * id);
  } while (freeIds.has(delId));
  freeIds.add(delId);
  delId = '' + delId;

  const delTs = unwrap(state, ['visitors', delId, 'ts']);
  // console.log('Unwrap', debug(state), ['visitors', delId, 'ts'], delTs);

  leave++;
  return graph(
    {
      visitors: { [delId]: null },
      visitorsByTime: { [delTs]: null },
    },
    ts,
  );
}
github usegraffy / graffy / src / core / shift.js View on Github external
async function shiftedNext(unwrappedNextPayload) {
      nextCalled = true;
      const nextPayload = wrap(unwrappedNextPayload, path);
      if (remainingPayload.length) merge(nextPayload, remainingPayload);
      const nextResult = await next(nextPayload);

      // Remember the next() results that are not returned to this provider.
      // These will be merged into the result later.
      remainingNextResult = remove(nextResult, path) || [];
      return unwrap(nextResult, path);
    }
github usegraffy / graffy / src / core / shift.js View on Github external
return async function* shiftedGen(payload, options, next) {
    let nextCalled = false;
    let remainingNextStream;
    const unwrappedPayload = unwrap(payload, path);
    const remainingPayload = remove(payload, path) || [];

    // TODO: This should probably use makeStream and propagate returns.
    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);
github usegraffy / graffy / src / core / shift.js View on Github external
return async function shiftedFn(payload, options, next) {
    let nextCalled = false;
    let remainingNextResult;
    const unwrappedPayload = unwrap(payload, path);
    const remainingPayload = remove(payload, path) || [];

    // This next function is offered to the provider function.
    async function shiftedNext(unwrappedNextPayload) {
      nextCalled = true;
      const nextPayload = wrap(unwrappedNextPayload, path);
      if (remainingPayload.length) merge(nextPayload, remainingPayload);
      const nextResult = await next(nextPayload);

      // Remember the next() results that are not returned to this provider.
      // These will be merged into the result later.
      remainingNextResult = remove(nextResult, path) || [];
      return unwrap(nextResult, path);
    }

    const result = wrap(await fn(unwrappedPayload, options, shiftedNext), path);
github usegraffy / graffy / src / core / resolve.js View on Github external
function run(i, payload) {
    if (i >= handlers.length) {
      throw Error('resolve.unfulfilled ' + JSON.stringify(payload));
    }

    const { path, handle } = handlers[i];
    if (!unwrap(payload, path)) return run(i + 1, payload);

    let nextCalled = false;
    return handle(payload, options, nextPayload => {
      if (nextCalled) throw Error('resolve.duplicate_next: ' + handle.name);
      nextCalled = true;
      return run(i + 1, nextPayload);
    });
  }
github usegraffy / graffy / src / core / Graffy.js View on Github external
call(type, unwrappedPayload, options) {
    const payload = wrap(unwrappedPayload, this.path);
    const result = this.core.call(type, payload, options);
    return unwrap(result, this.path);
  }
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;
      }
    };