How to use the @redux-saga/is.iterator function in @redux-saga/is

To help you get started, we’ve selected a few @redux-saga/is 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 jfairbank / redux-saga-test-plan / src / expectSaga / index.js View on Github external
if (providedValue !== value) {
          return providedValue;
        }

        // Because we manually consume the `call`, we need to manually store
        // the effect, so assertions on the `call` work.
        processEffect({
          effectId: nextSagaId(),
          effect: value,
        });

        const { context, fn, args } = effect;
        const result = fn.apply(context, args);

        if (is.iterator(result)) {
          return call(defaultSagaWrapper, result, refineYieldedValue);
        }

        return result;
      }

      // Ensure we wrap yielded iterators (i.e. `yield someInnerSaga()`) for
      // providers to work.
      case is.iterator(value):
        return useProvidedValue(defaultSagaWrapper(value, refineYieldedValue));

      default:
        return useProvidedValue(value);
    }
  }
github redux-saga / redux-saga / packages / core / src / internal / effectRunnerMap.js View on Github external
function createTaskIterator({ context, fn, args }) {
  // catch synchronous failures; see #152 and #441
  try {
    const result = fn.apply(context, args)

    // i.e. a generator function returns an iterator
    if (is.iterator(result)) {
      return result
    }

    let resolved = false

    const next = arg => {
      if (!resolved) {
        resolved = true
        // Only promises returned from fork will be interpreted. See #1573
        return { value: result, done: !is.promise(result) }
      } else {
        return { value: arg, done: true }
      }
    }

    return makeIterator(next)
github redux-saga / redux-saga / packages / core / src / internal / proc.js View on Github external
it allows this generator to propagate cancellation downward.

      ATTENTION! effect runners must setup the cancel logic by setting cb.cancel = [cancelMethod]
      And the setup must occur before calling the callback

      This is a sort of inversion of control: called async functions are responsible
      of completing the flow by calling the provided continuation; while caller functions
      are responsible for aborting the current flow by calling the attached cancel function

      Library users can attach their own cancellation logic to promises by defining a
      promise[CANCEL] method in their returned promises
      ATTENTION! calling cancel must have no effect on an already completed or cancelled effect
    **/
    if (is.promise(effect)) {
      resolvePromise(effect, currCb)
    } else if (is.iterator(effect)) {
      // resolve iterator
      proc(env, effect, task.context, effectId, meta, /* isRoot */ false, currCb)
    } else if (effect && effect[IO]) {
      const effectRunner = effectRunnerMap[effect.type]
      effectRunner(env, effect.payload, currCb, executingContext)
    } else {
      // anything else returned as is
      currCb(effect)
    }
  }
github redux-saga / redux-saga / packages / core / src / internal / effectRunnerMap.js View on Github external
function runCallEffect(env, { context, fn, args }, cb, { task }) {
  // catch synchronous failures; see #152
  try {
    const result = fn.apply(context, args)

    if (is.promise(result)) {
      resolvePromise(result, cb)
      return
    }

    if (is.iterator(result)) {
      // resolve iterator
      proc(env, result, task.context, currentEffectId, getMetaInfo(fn), /* isRoot */ false, cb)
      return
    }

    cb(result)
  } catch (error) {
    cb(error, true)
  }
}
github redux-saga / redux-saga / packages / simple-saga-monitor / src / modules / logSaga.js View on Github external
function getFormatterFromDescriptor(desc) {
  const isCancel = desc.status === CANCELLED
  const isError = desc.status === REJECTED

  const formatter = new DescriptorFormatter(isCancel, isError)

  const winnerInd = desc.winner ? (isError ? '✘' : '✓') : ''
  formatter.addLabel(winnerInd).addLabel(desc.label)

  if (desc.root) {
    formatter
      .addEffectType('root')
      .resetStyle()
      .addCall(desc.saga.name, desc.args)
      .addDescResult(desc)
  } else if (is.iterator(desc.effect)) {
    formatter.addValue(desc.effect.name).addDescResult(desc, true)
  } else if (is.promise(desc.effect)) {
    formatter
      .addEffectType('promise')
      .resetStyle()
      .addDescResult(desc)
  } else if (is.effect(desc.effect)) {
    const { type, payload } = desc.effect

    if (type === effectTypes.TAKE) {
      formatter
        .addEffectType('take')
        .resetStyle()
        .addValue(payload.channel == null ? payload.pattern : payload)
        .addDescResult(desc)
    } else if (type === effectTypes.PUT) {
github clarketm / saga-monitor / src / modules / logSaga.js View on Github external
function getFormatterFromDescriptor(desc, color) {
  const isCancel = desc.status === CANCELLED;
  const isError = desc.status === REJECTED;

  const formatter = new DescriptorFormatter(isCancel, isError, color);

  const winnerInd = desc.winner ? (isError ? "✘" : "✓") : "";
  formatter.addLabel(winnerInd).addLabel(desc.label);

  if (desc.root) {
    formatter
      .addEffectType("root")
      .resetStyle()
      .addCall(desc.saga.name, desc.args)
      .addDescResult(desc);
  } else if (is.iterator(desc.effect)) {
    formatter.addValue(desc.effect.name).addDescResult(desc, true);
  } else if (is.promise(desc.effect)) {
    formatter
      .addEffectType("promise")
      .resetStyle()
      .addDescResult(desc);
  } else if (is.effect(desc.effect)) {
    const { type, payload } = desc.effect;

    if (type === effectTypes.TAKE) {
      formatter
        .addEffectType("take")
        .resetStyle()
        .addValue(payload.channel == null ? payload.pattern : payload)
        .addDescResult(desc);
    } else if (type === effectTypes.PUT) {