UNPKG

@vslutov/of-type

Version:

Operator ofType for redux-observable, compatible with redux-batch-middleware

35 lines (28 loc) 831 B
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var operators = require('rxjs/operators'); var reduxBatchMiddleware = require('redux-batch-middleware'); const keyHasType = (type, key) => { return type === key || (typeof key === 'function' && type === key.toString()) }; const keysHasType = (type, keys) => { for (let key of keys) { if (keyHasType(type, key)) { return true } } return false }; const ofType = (...keys) => (source) => source.pipe( operators.mergeMap((action) => { if (keysHasType(action.type, keys)) { return [action] } if (action.type === reduxBatchMiddleware.type) { return action.payload.filter(subAction => keysHasType(subAction.type, keys)) } return [] }) ); exports.ofType = ofType; //# sourceMappingURL=index.js.map