UNPKG

redux-validate-fsa

Version:

Redux middleware that validates if an action is a Flux Standard Action (FSA)

44 lines (38 loc) 1.26 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); exports['default'] = fsa; var _fluxStandardAction = require('flux-standard-action'); /** * Creates a Redux middleware that validates if supplied actions are FSA-compliant. * * @param {Array|Function} ignore (optional) - an array of action types * that should be skipped from the FSA check or a predicate of type (Action) => bool * that should return true for actions that should be skipped from the FSA check. * * @returns {Function} A Redux middleware. */ function fsa(ignore) { var _ignore = (function () { if (!ignore) return function () { return false; }; if (typeof ignore === 'function') return ignore; if (Array.isArray(ignore)) return function (action) { return action && ~ignore.indexOf(action.type); }; throw new Error('\'ignore\' must be an array or function'); })(); return function (store) { return function (next) { return function (action) { if (_ignore(action) || action && (0, _fluxStandardAction.isFSA)(action)) { return next(action); } throw new Error('\'action\' must be an object and FSA compliant'); }; }; }; } module.exports = exports['default'];