How to use is-promise - 8 common examples

To help you get started, we’ve selected a few is-promise 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 posthtml / posthtml-cache / test / test-plugin.js View on Github external
test('should return promise', t => {
  t.true(isPromise(processing('')));
});
github kimjoar / expect-to / src / index.js View on Github external
to (test) {
      const res = test({ actual, assert })
      const throwIfError = throwIfErrorFn(actual)

      if (isPromise(res)) {
        return res.then(
          throwIfError,
          throwIfError
        )
      } else {
        throwIfError(res)
      }

      return this
    }
  }
github recruit-tech / redux-effects-steps / src / index.js View on Github external
function maybeDispatch(action) {
    if (!action || isPromise(action)) {
      return action;
    }

    if (Array.isArray(action)) {
      return action.filter(Boolean).map(dispatch);
    }

    return dispatch(action);
  }
github 10xjs / redux-promise-wait / src / enhancer.js View on Github external
dispatch(action) {
        const promise = handleAction(action);
        if (isPromise(promise)) {
          waitStore.dispatch(addAction(action, promise));
        }
        return store.dispatch(action);
      },
    };
github ecomfe / redux-managed-thunk / src / optimistic.js View on Github external
let isRollbackCompleted = false;
        let thunkWithRollback = (dispatch, ...args) => {
            let dispatchWithRollback = action => {
                if (isActualThunkReturned && !isRollbackCompleted) {
                    rollback(transactionId, next);
                    isRollbackCompleted = true;
                }

                return dispatch(action);
            };
            return actualThunk(dispatchWithRollback, ...args);
        };

        let actualThunkRunning = next(withTransaction(thunkWithRollback, null));

        if (!isPromise(actualThunkRunning)) {
            throw new Error('Actual thunk of optimistic action must be async');
        }

        isActualThunkReturned = true;

        let optimisticThunkReturn = next(withTransaction(optimisticThunk, transactionId));

        if (isPromise(optimisticThunkReturn)) {
            throw new Error('Optimistic thunk of optimistic action must be sync');
        }

        return actualThunkRunning;
    };
};
github jhnns / spa-vs-universal / universal / app / effects / executor.js View on Github external
return (effect, ...args) => {
        const result = effect(store)(...args);

        if (isPromise(result) === true) {
            const promise = result;

            store.dispatch(effectState.actions.addPendingEffect(effect, args, promise));
            promise.then(
                res => {
                    store.dispatch(effectState.actions.removePendingEffect(effect, args, promise));

                    return res;
                },
                err => {
                    store.dispatch(effectState.actions.removePendingEffect(effect, args, promise));

                    throw err;
                }
            );
        }
github recruit-tech / redux-effects-steps / src / index.js View on Github external
function createAction(actionOrCreator, param) {
  if (!actionOrCreator || isPromise(actionOrCreator)) {
    return null;
  }

  if (typeof actionOrCreator === 'function') {
    return actionOrCreator(param);
  }

  return actionOrCreator;
}
github recruit-tech / redux-pluto / src / shared / packages / redux-effects-ext / index.js View on Github external
function promisify(val) {
  if (isPromise(val)) {
    return val;
  }

  if (Array.isArray(val)) {
    return Promise.all(val.map(promisify));
  }

  return !isErrorAction(val) ? Promise.resolve(val) : Promise.reject(val.payload);
}

is-promise

Test whether an object looks like a promises-a+ promise

MIT
Latest version published 5 years ago

Package Health Score

74 / 100
Full package analysis

Popular is-promise functions