Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('should return promise', t => {
t.true(isPromise(processing('')));
});
to (test) {
const res = test({ actual, assert })
const throwIfError = throwIfErrorFn(actual)
if (isPromise(res)) {
return res.then(
throwIfError,
throwIfError
)
} else {
throwIfError(res)
}
return this
}
}
function maybeDispatch(action) {
if (!action || isPromise(action)) {
return action;
}
if (Array.isArray(action)) {
return action.filter(Boolean).map(dispatch);
}
return dispatch(action);
}
dispatch(action) {
const promise = handleAction(action);
if (isPromise(promise)) {
waitStore.dispatch(addAction(action, promise));
}
return store.dispatch(action);
},
};
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;
};
};
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;
}
);
}
function createAction(actionOrCreator, param) {
if (!actionOrCreator || isPromise(actionOrCreator)) {
return null;
}
if (typeof actionOrCreator === 'function') {
return actionOrCreator(param);
}
return actionOrCreator;
}
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);
}