UNPKG

fluorine-lib

Version:

Reactive state and side effect management for React using a single stream of actions

29 lines (23 loc) 837 B
import { map } from 'rxjs/operator/map'; import isObservable from '../util/isObservable'; import isPromise from '../util/isPromise'; export function createThunkMiddleware() { for (var _len = arguments.length, extraArgs = Array(_len), _key = 0; _key < _len; _key++) { extraArgs[_key] = arguments[_key]; } return function (dispatcher) { return function (agenda) { return map.call(agenda, function (thunkish) { if (typeof thunkish === 'function') { var res = thunkish.apply(undefined, [dispatcher.next.bind(dispatcher), dispatcher.reduce.bind(dispatcher)].concat(extraArgs)); if (isObservable(res) || isPromise(res)) { dispatcher.next(res); } return null; } return thunkish; }); }; }; } export default createThunkMiddleware();