Socket
Socket
Sign inDemoInstall

typesafe-actions

Package Overview
Dependencies
0
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.4.2 to 5.0.0-0

17

dist/create-reducer.d.ts
import { Reducer, Action, Types } from './type-helpers';
declare type CreateReducerChainApi<TState, TPrevNotHandledAction extends Action, TRootAction extends Action> = <TType extends TPrevNotHandledAction['type'], TCreator extends (...args: any[]) => TPrevNotHandledAction, TNextNotHandledAction extends Exclude<TPrevNotHandledAction, Action<TType> & ReturnType<TCreator>>, TAction extends TPrevNotHandledAction extends Action<TType> ? TPrevNotHandledAction extends ReturnType<TCreator> ? TPrevNotHandledAction : never : never>(singleOrMultipleCreatorsAndTypes: TType | TType[] | TCreator | TCreator[], reducer: (state: TState, action: TAction) => TState) => [TNextNotHandledAction] extends [never] ? Reducer<TState, TRootAction> & {
declare type HandleActionChainApi<TState, TInputAction extends Action, TRootAction extends Action> = <TActionCreator extends (...args: any[]) => TInputAction, THandledAction extends ReturnType<TActionCreator>, TOutputAction extends Exclude<TInputAction, THandledAction>>(singleOrMultipleCreatorsAndTypes: TActionCreator | TActionCreator[], reducer: (state: TState, action: THandledAction) => TState) => [TOutputAction] extends [never] ? Reducer<TState, TRootAction> & {
handlers: Record<TRootAction['type'], (state: TState, action: TRootAction) => TState>;
} : Reducer<TState, TRootAction> & {
handlers: Record<Exclude<TRootAction, TNextNotHandledAction>['type'], (state: TState, action: TRootAction) => TState>;
handleAction: CreateReducerChainApi<TState, TNextNotHandledAction, TRootAction>;
handlers: Record<Exclude<TRootAction, TOutputAction>['type'], (state: TState, action: TRootAction) => TState>;
handleAction: HandleActionChainApi<TState, TOutputAction, TRootAction>;
handleType: HandleTypeChainApi<TState, TOutputAction, TRootAction>;
};
declare type HandleTypeChainApi<TState, TInputAction extends Action, TRootAction extends Action> = <TType extends TInputAction['type'], THandledAction extends Extract<TInputAction, Action<TType>>, TOutputAction extends Exclude<TInputAction, THandledAction>>(singleOrMultipleCreatorsAndTypes: TType | TType[], reducer: (state: TState, action: THandledAction) => TState) => [TOutputAction] extends [never] ? Reducer<TState, TRootAction> & {
handlers: Record<TRootAction['type'], (state: TState, action: TRootAction) => TState>;
} : Reducer<TState, TRootAction> & {
handlers: Record<Exclude<TRootAction, TOutputAction>['type'], (state: TState, action: TRootAction) => TState>;
handleAction: HandleActionChainApi<TState, TOutputAction, TRootAction>;
handleType: HandleTypeChainApi<TState, TOutputAction, TRootAction>;
};
declare type GetAction<TAction extends Action, TType extends TAction['type']> = TAction extends Action<TType> ? TAction : never;

@@ -17,4 +25,5 @@ declare type InitialHandler<TState, TRootAction extends Action> = {

readonly handlers: any;
readonly handleAction: CreateReducerChainApi<TState, TRootAction, TRootAction>;
readonly handleAction: HandleActionChainApi<TState, TRootAction, TRootAction>;
readonly handleType: HandleTypeChainApi<TState, TRootAction, TRootAction>;
};
export {};

@@ -29,3 +29,3 @@ /**

*/
export declare type ActionCreator<TType extends TypeConstant> = (...args: any[]) => Action<TType>;
export declare type ActionCreator<TType extends TypeConstant = TypeConstant> = (...args: any[]) => Action<TType>;
/**

@@ -32,0 +32,0 @@ * @desc Type representing Generic Reducer

@@ -209,3 +209,3 @@ 'use strict';

var handleAction = function handleAction(singleOrMultipleCreatorsAndTypes, reducer) {
var reducerHandler = function reducerHandler(singleOrMultipleCreatorsAndTypes, reducer) {
var creatorsAndTypes = Array.isArray(singleOrMultipleCreatorsAndTypes) ? singleOrMultipleCreatorsAndTypes : [singleOrMultipleCreatorsAndTypes];

@@ -223,3 +223,4 @@ var newHandlers = {};

handlers: Object.assign({}, handlers),
handleAction: handleAction
handleAction: reducerHandler,
handleType: reducerHandler
});

@@ -226,0 +227,0 @@ return chainApi;

@@ -1,2 +0,2 @@

"use strict";function n(n,t){return void 0===t&&(t=1),null==n}function t(n){throw void 0===n&&(n=1),new Error("Argument "+n+" is empty.")}function r(n){return"function"==typeof n&&"getType"in n}function e(n){throw void 0===n&&(n=1),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 i(n){return"string"==typeof n||"symbol"==typeof n}function u(n){return!i(n)}function c(n){throw void 0===n&&(n=1),new Error("Argument "+n+" is invalid, it should be an action type of type: string | symbol")}function a(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(r,o,i,c){return n(r)&&t(1),u(r)&&e(1),{type:r,payload:o,meta:i,error:c}}function f(r,e){n(r)&&t(1),u(r)&&c(1);var o=null!=e?e(r):function(){return{type:r}};return Object.assign(o,{getType:function(){return r},toString:function(){return r}})}function y(r){return n(r)&&t(1),u(r)&&c(1),Object.assign(function(){return f(r,function(n){return function(t,r){return{type:n,payload:t,meta:r}}})},{map:function(n){return f(r,function(t){return function(r,e){return Object.assign(n(r,e),{type:t})}})}})}function p(o){return n(o)&&t(1),r(o)||e(1),o.getType()}exports.action=s,exports.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}})},exports.createActionDeprecated=function(n,t){var r;if(null!=t){if("function"!=typeof t)throw new Error("second argument is not a function");r=t}else r=function(){return{type:n}};if(null==n)throw new Error("first argument is missing");if("string"!=typeof n&&"symbol"!=typeof n)throw new Error("first argument should be type of: string | symbol");return r},exports.createAsyncAction=function(n,t,r,e){return[n,t,r].forEach(a),Object.assign(function(){return{request:y(n)(),success:y(t)(),failure:y(r)(),cancel:e&&y(e)()}},{})},exports.createCustomAction=f,exports.createReducer=function n(t,e){void 0===e&&(e={});var o=Object.assign({},e);return Object.assign(function(n,r){if(void 0===n&&(n=t),o.hasOwnProperty(r.type)){var e=o[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({},o),handleAction:function(e,u){var c=Array.isArray(e)?e:[e],a={};return c.map(function(n){return r(n)?p(n):i(n)?n:function(n){throw void 0===n&&(n=1),new Error("Argument "+n+' is invalid, it should be an action-creator instance from "typesafe-actions" or action type of type: string | symbol')}()}).forEach(function(n){return a[n]=u}),n(t,Object.assign({},o,a))}})},exports.createStandardAction=y,exports.getType=p,exports.isActionOf=function(r,e){n(r)&&t(1);var i=Array.isArray(r)?r:[r];i.forEach(o);var u=function(n){return i.some(function(t){return n.type===t.getType()})};return void 0===e?u:u(e)},exports.isOfType=function(r,e){n(r)&&t(1);var o=Array.isArray(r)?r:[r];o.forEach(a);var i=function(n){return o.includes(n.type)};return void 0===e?i:i(e)};
"use strict";function n(n,t){return void 0===t&&(t=1),null==n}function t(n){throw void 0===n&&(n=1),new Error("Argument "+n+" is empty.")}function r(n){return"function"==typeof n&&"getType"in n}function e(n){throw void 0===n&&(n=1),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 i(n){return"string"==typeof n||"symbol"==typeof n}function u(n){return!i(n)}function c(n){throw void 0===n&&(n=1),new Error("Argument "+n+" is invalid, it should be an action type of type: string | symbol")}function a(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(r,o,i,c){return n(r)&&t(1),u(r)&&e(1),{type:r,payload:o,meta:i,error:c}}function f(r,e){n(r)&&t(1),u(r)&&c(1);var o=null!=e?e(r):function(){return{type:r}};return Object.assign(o,{getType:function(){return r},toString:function(){return r}})}function y(r){return n(r)&&t(1),u(r)&&c(1),Object.assign(function(){return f(r,function(n){return function(t,r){return{type:n,payload:t,meta:r}}})},{map:function(n){return f(r,function(t){return function(r,e){return Object.assign(n(r,e),{type:t})}})}})}function p(o){return n(o)&&t(1),r(o)||e(1),o.getType()}exports.action=s,exports.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}})},exports.createActionDeprecated=function(n,t){var r;if(null!=t){if("function"!=typeof t)throw new Error("second argument is not a function");r=t}else r=function(){return{type:n}};if(null==n)throw new Error("first argument is missing");if("string"!=typeof n&&"symbol"!=typeof n)throw new Error("first argument should be type of: string | symbol");return r},exports.createAsyncAction=function(n,t,r,e){return[n,t,r].forEach(a),Object.assign(function(){return{request:y(n)(),success:y(t)(),failure:y(r)(),cancel:e&&y(e)()}},{})},exports.createCustomAction=f,exports.createReducer=function n(t,e){void 0===e&&(e={});var o=Object.assign({},e),u=function(e,u){var c=Array.isArray(e)?e:[e],a={};return c.map(function(n){return r(n)?p(n):i(n)?n:function(n){throw void 0===n&&(n=1),new Error("Argument "+n+' is invalid, it should be an action-creator instance from "typesafe-actions" or action type of type: string | symbol')}()}).forEach(function(n){return a[n]=u}),n(t,Object.assign({},o,a))};return Object.assign(function(n,r){if(void 0===n&&(n=t),o.hasOwnProperty(r.type)){var e=o[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({},o),handleAction:u,handleType:u})},exports.createStandardAction=y,exports.getType=p,exports.isActionOf=function(r,e){n(r)&&t(1);var i=Array.isArray(r)?r:[r];i.forEach(o);var u=function(n){return i.some(function(t){return n.type===t.getType()})};return void 0===e?u:u(e)},exports.isOfType=function(r,e){n(r)&&t(1);var o=Array.isArray(r)?r:[r];o.forEach(a);var i=function(n){return o.includes(n.type)};return void 0===e?i:i(e)};
//# sourceMappingURL=typesafe-actions.cjs.production.js.map

@@ -1,2 +0,2 @@

function n(n,t){return void 0===t&&(t=1),null==n}function t(n){throw void 0===n&&(n=1),new Error("Argument "+n+" is empty.")}function r(n){return"function"==typeof n&&"getType"in n}function e(n){throw void 0===n&&(n=1),new Error("Argument "+n+' is invalid, it should be an action-creator instance from "typesafe-actions"')}function i(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 o(n){return"string"==typeof n||"symbol"==typeof n}function u(n){return!o(n)}function a(n){throw void 0===n&&(n=1),new Error("Argument "+n+" is invalid, it should be an action type of type: string | symbol")}function c(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 f(r,i,o,a){return n(r)&&t(1),u(r)&&e(1),{type:r,payload:i,meta:o,error:a}}function s(n,t){var r=null==t?function(){return f(n)}:t(f.bind(null,n));return Object.assign(r,{getType:function(){return n},toString:function(){return n}})}function y(r,e){n(r)&&t(1),u(r)&&a(1);var i=null!=e?e(r):function(){return{type:r}};return Object.assign(i,{getType:function(){return r},toString:function(){return r}})}function l(r){return n(r)&&t(1),u(r)&&a(1),Object.assign(function(){return y(r,function(n){return function(t,r){return{type:n,payload:t,meta:r}}})},{map:function(n){return y(r,function(t){return function(r,e){return Object.assign(n(r,e),{type:t})}})}})}function p(n,t,r,e){[n,t,r].forEach(c);return Object.assign(function(){return{request:l(n)(),success:l(t)(),failure:l(r)(),cancel:e&&l(e)()}},{})}function g(i){return n(i)&&t(1),r(i)||e(1),i.getType()}function d(n,t){void 0===t&&(t={});var e=Object.assign({},t);return Object.assign(function(t,r){if(void 0===t&&(t=n),e.hasOwnProperty(r.type)){var i=e[r.type];if("function"!=typeof i)throw Error('Reducer under "'+r.type+'" key is not a valid reducer');return i(t,r)}return t},{handlers:Object.assign({},e),handleAction:function(t,i){var u=Array.isArray(t)?t:[t],a={};return u.map(function(n){return r(n)?g(n):o(n)?n:function(n){throw void 0===n&&(n=1),new Error("Argument "+n+' is invalid, it should be an action-creator instance from "typesafe-actions" or action type of type: string | symbol')}()}).forEach(function(n){return a[n]=i}),d(n,Object.assign({},e,a))}})}function m(r,e){n(r)&&t(1);var i=Array.isArray(r)?r:[r];i.forEach(c);var o=function(n){return i.includes(n.type)};return void 0===e?o:o(e)}function h(r,e){n(r)&&t(1);var o=Array.isArray(r)?r:[r];o.forEach(i);var u=function(n){return o.some(function(t){return n.type===t.getType()})};return void 0===e?u:u(e)}function w(n,t){var r;if(null!=t){if("function"!=typeof t)throw new Error("second argument is not a function");r=t}else r=function(){return{type:n}};if(null==n)throw new Error("first argument is missing");if("string"!=typeof n&&"symbol"!=typeof n)throw new Error("first argument should be type of: string | symbol");return r}export{f as action,s as createAction,w as createActionDeprecated,p as createAsyncAction,y as createCustomAction,d as createReducer,l as createStandardAction,g as getType,h as isActionOf,m as isOfType};
function n(n,t){return void 0===t&&(t=1),null==n}function t(n){throw void 0===n&&(n=1),new Error("Argument "+n+" is empty.")}function r(n){return"function"==typeof n&&"getType"in n}function e(n){throw void 0===n&&(n=1),new Error("Argument "+n+' is invalid, it should be an action-creator instance from "typesafe-actions"')}function i(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 o(n){return"string"==typeof n||"symbol"==typeof n}function u(n){return!o(n)}function a(n){throw void 0===n&&(n=1),new Error("Argument "+n+" is invalid, it should be an action type of type: string | symbol")}function c(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 f(r,i,o,a){return n(r)&&t(1),u(r)&&e(1),{type:r,payload:i,meta:o,error:a}}function s(n,t){var r=null==t?function(){return f(n)}:t(f.bind(null,n));return Object.assign(r,{getType:function(){return n},toString:function(){return n}})}function y(r,e){n(r)&&t(1),u(r)&&a(1);var i=null!=e?e(r):function(){return{type:r}};return Object.assign(i,{getType:function(){return r},toString:function(){return r}})}function l(r){return n(r)&&t(1),u(r)&&a(1),Object.assign(function(){return y(r,function(n){return function(t,r){return{type:n,payload:t,meta:r}}})},{map:function(n){return y(r,function(t){return function(r,e){return Object.assign(n(r,e),{type:t})}})}})}function p(n,t,r,e){[n,t,r].forEach(c);return Object.assign(function(){return{request:l(n)(),success:l(t)(),failure:l(r)(),cancel:e&&l(e)()}},{})}function d(i){return n(i)&&t(1),r(i)||e(1),i.getType()}function g(n,t){void 0===t&&(t={});var e=Object.assign({},t),i=function(t,i){var u=Array.isArray(t)?t:[t],a={};return u.map(function(n){return r(n)?d(n):o(n)?n:function(n){throw void 0===n&&(n=1),new Error("Argument "+n+' is invalid, it should be an action-creator instance from "typesafe-actions" or action type of type: string | symbol')}()}).forEach(function(n){return a[n]=i}),g(n,Object.assign({},e,a))};return Object.assign(function(t,r){if(void 0===t&&(t=n),e.hasOwnProperty(r.type)){var i=e[r.type];if("function"!=typeof i)throw Error('Reducer under "'+r.type+'" key is not a valid reducer');return i(t,r)}return t},{handlers:Object.assign({},e),handleAction:i,handleType:i})}function m(r,e){n(r)&&t(1);var i=Array.isArray(r)?r:[r];i.forEach(c);var o=function(n){return i.includes(n.type)};return void 0===e?o:o(e)}function h(r,e){n(r)&&t(1);var o=Array.isArray(r)?r:[r];o.forEach(i);var u=function(n){return o.some(function(t){return n.type===t.getType()})};return void 0===e?u:u(e)}function w(n,t){var r;if(null!=t){if("function"!=typeof t)throw new Error("second argument is not a function");r=t}else r=function(){return{type:n}};if(null==n)throw new Error("first argument is missing");if("string"!=typeof n&&"symbol"!=typeof n)throw new Error("first argument should be type of: string | symbol");return r}export{f as action,s as createAction,w as createActionDeprecated,p as createAsyncAction,y as createCustomAction,g as createReducer,l as createStandardAction,d as getType,h as isActionOf,m as isOfType};
//# sourceMappingURL=typesafe-actions.es.production.js.map

@@ -213,3 +213,3 @@ (function (global, factory) {

var handleAction = function handleAction(singleOrMultipleCreatorsAndTypes, reducer) {
var reducerHandler = function reducerHandler(singleOrMultipleCreatorsAndTypes, reducer) {
var creatorsAndTypes = Array.isArray(singleOrMultipleCreatorsAndTypes) ? singleOrMultipleCreatorsAndTypes : [singleOrMultipleCreatorsAndTypes];

@@ -227,3 +227,4 @@ var newHandlers = {};

handlers: Object.assign({}, handlers),
handleAction: handleAction
handleAction: reducerHandler,
handleType: reducerHandler
});

@@ -230,0 +231,0 @@ return chainApi;

@@ -1,2 +0,2 @@

!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,t){return void 0===t&&(t=1),null==n}function r(n){throw void 0===n&&(n=1),new Error("Argument "+n+" is empty.")}function e(n){return"function"==typeof n&&"getType"in n}function i(n){throw void 0===n&&(n=1),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 c(n){return!u(n)}function a(n){throw void 0===n&&(n=1),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),c(n)&&i(1),{type:n,payload:e,meta:o,error:u}}function y(n,e){t(n)&&r(1),c(n)&&a(1);var i=null!=e?e(n):function(){return{type:n}};return Object.assign(i,{getType:function(){return n},toString:function(){return n}})}function p(n){return t(n)&&r(1),c(n)&&a(1),Object.assign(function(){return y(n,function(n){return function(t,r){return{type:n,payload:t,meta:r}}})},{map:function(t){return y(n,function(n){return function(r,e){return Object.assign(t(r,e),{type:n})}})}})}function l(n){return t(n)&&r(1),e(n)||i(1),n.getType()}n.action=s,n.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}})},n.createActionDeprecated=function(n,t){var r;if(null!=t){if("function"!=typeof t)throw new Error("second argument is not a function");r=t}else r=function(){return{type:n}};if(null==n)throw new Error("first argument is missing");if("string"!=typeof n&&"symbol"!=typeof n)throw new Error("first argument should be type of: string | symbol");return r},n.createAsyncAction=function(n,t,r,e){return[n,t,r].forEach(f),Object.assign(function(){return{request:p(n)(),success:p(t)(),failure:p(r)(),cancel:e&&p(e)()}},{})},n.createCustomAction=y,n.createReducer=function n(t,r){void 0===r&&(r={});var i=Object.assign({},r);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:function(r,o){var c=Array.isArray(r)?r:[r],a={};return c.map(function(n){return e(n)?l(n):u(n)?n:function(n){throw void 0===n&&(n=1),new Error("Argument "+n+' is invalid, it should be an action-creator instance from "typesafe-actions" or action type of type: string | symbol')}()}).forEach(function(n){return a[n]=o}),n(t,Object.assign({},i,a))}})},n.createStandardAction=p,n.getType=l,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)}});
!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,t){return void 0===t&&(t=1),null==n}function r(n){throw void 0===n&&(n=1),new Error("Argument "+n+" is empty.")}function e(n){return"function"==typeof n&&"getType"in n}function i(n){throw void 0===n&&(n=1),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 c(n){return!u(n)}function a(n){throw void 0===n&&(n=1),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),c(n)&&i(1),{type:n,payload:e,meta:o,error:u}}function y(n,e){t(n)&&r(1),c(n)&&a(1);var i=null!=e?e(n):function(){return{type:n}};return Object.assign(i,{getType:function(){return n},toString:function(){return n}})}function p(n){return t(n)&&r(1),c(n)&&a(1),Object.assign(function(){return y(n,function(n){return function(t,r){return{type:n,payload:t,meta:r}}})},{map:function(t){return y(n,function(n){return function(r,e){return Object.assign(t(r,e),{type:n})}})}})}function l(n){return t(n)&&r(1),e(n)||i(1),n.getType()}n.action=s,n.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}})},n.createActionDeprecated=function(n,t){var r;if(null!=t){if("function"!=typeof t)throw new Error("second argument is not a function");r=t}else r=function(){return{type:n}};if(null==n)throw new Error("first argument is missing");if("string"!=typeof n&&"symbol"!=typeof n)throw new Error("first argument should be type of: string | symbol");return r},n.createAsyncAction=function(n,t,r,e){return[n,t,r].forEach(f),Object.assign(function(){return{request:p(n)(),success:p(t)(),failure:p(r)(),cancel:e&&p(e)()}},{})},n.createCustomAction=y,n.createReducer=function n(t,r){void 0===r&&(r={});var i=Object.assign({},r),o=function(r,o){var c=Array.isArray(r)?r:[r],a={};return c.map(function(n){return e(n)?l(n):u(n)?n:function(n){throw void 0===n&&(n=1),new Error("Argument "+n+' is invalid, it should be an action-creator instance from "typesafe-actions" or action type of type: string | symbol')}()}).forEach(function(n){return a[n]=o}),n(t,Object.assign({},i,a))};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.createStandardAction=p,n.getType=l,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)}});
//# sourceMappingURL=typesafe-actions.umd.production.js.map
{
"name": "typesafe-actions",
"version": "4.4.2",
"version": "5.0.0-0",
"description": "Typesafe Action Creators for Redux / Flux Architectures (in TypeScript)",

@@ -37,5 +37,4 @@ "author": "Piotr Witek <piotrek.witek@gmail.com> (http://piotrwitek.github.io)",

"prepublishOnly": "npm run reinstall && npm run ci-check && npm run build",
"benchmark:2": " node --max-old-space-size=8000 ./node_modules/.bin/tsc --diagnostics --outDir out benchmarks/2-actions.ts && rm -rf out",
"benchmark:10": "node --max-old-space-size=8000 ./node_modules/.bin/tsc --diagnostics --outDir out benchmarks/10-actions.ts && rm -rf out",
"benchmark:50": "node --max-old-space-size=8000 ./node_modules/.bin/tsc --diagnostics --outDir out benchmarks/50-actions.ts && rm -rf out"
"benchmark:150": "node --max-old-space-size=8000 ./node_modules/.bin/tsc --diagnostics --outDir out benchmarks/150-actions.ts && rm -rf out"
},

@@ -42,0 +41,0 @@ "devDependencies": {

@@ -39,3 +39,3 @@ <div align="center">

- **focus on quality** - complete test-suite for an entire API surface containing regular runtime tests and extra type-tests to guarantee **type soundness** and to prevent regressions in the future TypeScript versions
- **focus on performance** - integrated performance benchmarks to guarantee that the computational complexity of types are in check and there are no slow-downs when your application grow `npm run benchmark:[2,10,50]`
- **focus on performance** - integrated performance benchmarks to guarantee that the computational complexity of types are in check and there are no slow-downs when your application grow `npm run benchmark:XXX`

@@ -784,6 +784,8 @@

createReducer<TState, TRootAction>(initialState, handlersMap?)
.handleAction(type, reducer)
.handleAction([type1, type2, ...typeN], reducer)
// or
createReducer<TState, TRootAction>(initialState)
.handleAction(actionCreator, reducer)
.handleAction([actionCreator1, actionCreator2, ...actionCreatorN], reducer)
.handleType(type, reducer)
.handleType([type1, type2, ...typeN], reducer)
```

@@ -803,3 +805,3 @@

Using type-constants as keys in the object map:
**Object map style:**
```ts

@@ -815,8 +817,5 @@ import { createReducer, getType } from 'typesafe-actions'

})
counterReducer(0, add(4)); // => 4
counterReducer(0, increment()); // => 1
```
Using handleAction chain API:
**Chain API style:**
```ts

@@ -835,10 +834,7 @@ // using action-creators

const counterReducer = createReducer<State, Action>(0)
.handleAction('ADD', (state, action) => state + action.payload)
.handleAction('INCREMENT', (state, _) => state + 1);
counterReducer(0, add(4)); // => 4
counterReducer(0, increment()); // => 1
.handleType('ADD', (state, action) => state + action.payload)
.handleType('INCREMENT', (state, _) => state + 1);
```
Extend or compose various reducers together - every operation is completely typesafe:
**Extend or compose reducers - every operation is completely typesafe:**
```ts

@@ -845,0 +841,0 @@ const newCounterReducer = createReducer<State, Action>(0)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc