UNPKG

4.14 kBJavaScriptView Raw
1!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n=n||self).TypesafeActions={})}(this,(function(n){"use strict";function t(n){return null==n}function r(n){throw new Error("Argument "+n+" is empty.")}function e(n){return"function"==typeof n&&"getType"in n}function i(n){throw new Error("Argument "+n+' is invalid, it should be an action-creator instance from "typesafe-actions"')}function o(n,t){if(null==n)throw new Error("Argument contains array with empty element at index "+t);if(null==n.getType)throw new Error("Argument contains array with invalid element at index "+t+', it should be an action-creator instance from "typesafe-actions"')}function u(n){return"string"==typeof n||"symbol"==typeof n}function a(n){return!u(n)}function c(n){throw new Error("Argument "+n+" is invalid, it should be an action type of type: string | symbol")}function f(n,t){if(null==n)throw new Error("Argument contains array with empty element at index "+t);if("string"!=typeof n&&"symbol"!=typeof n)throw new Error("Argument contains array with invalid element at index "+t+", it should be of type: string | symbol")}function s(n,e,o,u){return t(n)&&r(1),a(n)&&i(1),{type:n,payload:e,meta:o,error:u}}function y(n,e){t(n)&&r(1),a(n)&&c(1);return Object.assign((function(){var t=null!=e?e.apply(void 0,arguments):void 0;return Object.assign({type:n},t)}),{getType:function(){return n},toString:function(){return n}})}function l(n,e,i){return t(n)&&r(1),a(n)&&c(1),function(){return y(n,(function(){var n=arguments.length<=0?void 0:arguments[0],t=arguments.length<=1?void 0:arguments[1];return null==e&&null==i||(n=null!=e?e.apply(void 0,arguments):void 0,t=null!=i?i.apply(void 0,arguments):void 0),Object.assign({},void 0!==n&&{payload:n},{},void 0!==t&&{meta:t})}))}}function p(n){return t(n)&&r(1),e(n)||i(1),n.getType()}function d(n,e){t(n)&&r(1),a(n)&&c(1);var i=null!=e?e(n):function(){return{type:n}};return Object.assign(i,{getType:function(){return n},toString:function(){return n}})}var g={createAction:function(n,t){var r=null==t?function(){return s(n)}:t(s.bind(null,n));return Object.assign(r,{getType:function(){return n},toString:function(){return n}})},createCustomAction:d,createStandardAction:function(n){return t(n)&&r(1),a(n)&&c(1),Object.assign((function(){return d(n,(function(n){return function(t,r){return{type:n,payload:t,meta:r}}}))}),{map:function(t){return d(n,(function(n){return function(r,e){return Object.assign(t(r,e),{type:n})}}))}})}};n.action=s,n.createAction=l,n.createAsyncAction=function(n,t,r,e){return function(){var i=[n,t,r,e].map((function(n,t){return Array.isArray(n)?l(n[0],n[1],n[2])():"string"==typeof n||"symbol"==typeof n?l(n)():void(t<3&&function(n){throw new Error("Argument "+n+' is invalid, it should be an action type of "string | symbol" or a tuple of "[string | symbol, Function, Function?]"')}(t))}));return{request:i[0],success:i[1],failure:i[2],cancel:i[3]}}},n.createCustomAction=y,n.createReducer=function n(t,r){void 0===r&&(r={});var i=Object.assign({},r),o=function(r,o){var a=Array.isArray(r)?r:[r],c={};return a.map((function(n,t){return e(n)?p(n):u(n)?n:function(n){throw new Error("Argument "+n+' is invalid, it should be an action-creator instance from "typesafe-actions" or action type of type: string | symbol')}(t+1)})).forEach((function(n){return c[n]=o})),n(t,Object.assign({},i,{},c))};return Object.assign((function(n,r){if(void 0===n&&(n=t),i.hasOwnProperty(r.type)){var e=i[r.type];if("function"!=typeof e)throw Error('Reducer under "'+r.type+'" key is not a valid reducer');return e(n,r)}return n}),{handlers:Object.assign({},i),handleAction:o,handleType:o})},n.deprecated=g,n.getType=p,n.isActionOf=function(n,e){t(n)&&r(1);var i=Array.isArray(n)?n:[n];i.forEach(o);var u=function(n){return i.some((function(t){return n.type===t.getType()}))};return void 0===e?u:u(e)},n.isOfType=function(n,e){t(n)&&r(1);var i=Array.isArray(n)?n:[n];i.forEach(f);var o=function(n){return i.includes(n.type)};return void 0===e?o:o(e)}}));
2//# sourceMappingURL=typesafe-actions.umd.production.js.map