@evertbouw/redux-toolkit
Version:
Redux toolkit but without immer
3 lines (2 loc) • 12.7 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).RTK={})}(this,(function(e){"use strict";var t=function(e){var t,r=("undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof module?module:Function("return this")()).Symbol;return"function"==typeof r?r.observable?t=r.observable:(t=r("observable"),r.observable=t):t="@@observable",t}(),r=function(){return Math.random().toString(36).substring(7).split("").join(".")},n={INIT:"@@redux/INIT"+r(),REPLACE:"@@redux/REPLACE"+r(),PROBE_UNKNOWN_ACTION:function(){return"@@redux/PROBE_UNKNOWN_ACTION"+r()}};function o(e){if("object"!=typeof e||null===e)return!1;for(var t=e;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function i(e,r,a){var u;if("function"==typeof r&&"function"==typeof a||"function"==typeof a&&"function"==typeof arguments[3])throw new Error("It looks like you are passing several store enhancers to createStore(). This is not supported. Instead, compose them together to a single function");if("function"==typeof r&&void 0===a&&(a=r,r=void 0),void 0!==a){if("function"!=typeof a)throw new Error("Expected the enhancer to be a function.");return a(i)(e,r)}if("function"!=typeof e)throw new Error("Expected the reducer to be a function.");var c=e,f=r,s=[],d=s,l=!1;function p(){d===s&&(d=s.slice())}function y(){if(l)throw new Error("You may not call store.getState() while the reducer is executing. The reducer has already received the state as an argument. Pass it down from the top reducer instead of reading it from the store.");return f}function h(e){if("function"!=typeof e)throw new Error("Expected the listener to be a function.");if(l)throw new Error("You may not call store.subscribe() while the reducer is executing. If you would like to be notified after the store has been updated, subscribe from a component and invoke store.getState() in the callback to access the latest state. See https://redux.js.org/api-reference/store#subscribe(listener) for more details.");var t=!0;return p(),d.push(e),function(){if(t){if(l)throw new Error("You may not unsubscribe from a store listener while the reducer is executing. See https://redux.js.org/api-reference/store#subscribe(listener) for more details.");t=!1,p();var r=d.indexOf(e);d.splice(r,1)}}}function v(e){if(!o(e))throw new Error("Actions must be plain objects. Use custom middleware for async actions.");if(void 0===e.type)throw new Error('Actions may not have an undefined "type" property. Have you misspelled a constant?');if(l)throw new Error("Reducers may not dispatch actions.");try{l=!0,f=c(f,e)}finally{l=!1}for(var t=s=d,r=0;r<t.length;r++)(0,t[r])();return e}function b(e){if("function"!=typeof e)throw new Error("Expected the nextReducer to be a function.");c=e,v({type:n.REPLACE})}function w(){var e,r=h;return(e={subscribe:function(e){if("object"!=typeof e||null===e)throw new TypeError("Expected the observer to be an object.");function t(){e.next&&e.next(y())}return t(),{unsubscribe:r(t)}}})[t]=function(){return this},e}return v({type:n.INIT}),(u={dispatch:v,subscribe:h,getState:y,replaceReducer:b})[t]=w,u}function a(e,t){var r=t&&t.type;return"Given "+(r&&'action "'+String(r)+'"'||"an action")+', reducer "'+e+'" returned undefined. To ignore an action, you must explicitly return the previous state. If you want this reducer to hold no value, you can return null instead of undefined.'}function u(e){for(var t=Object.keys(e),r={},o=0;o<t.length;o++){var i=t[o];"function"==typeof e[i]&&(r[i]=e[i])}var u,c=Object.keys(r);try{!function(e){Object.keys(e).forEach((function(t){var r=e[t];if(void 0===r(void 0,{type:n.INIT}))throw new Error('Reducer "'+t+"\" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined.");if(void 0===r(void 0,{type:n.PROBE_UNKNOWN_ACTION()}))throw new Error('Reducer "'+t+"\" returned undefined when probed with a random type. Don't try to handle "+n.INIT+' or other actions in "redux/*" namespace. They are considered private. Instead, you must return the current state for any unknown actions, unless it is undefined, in which case you must return the initial state, regardless of the action type. The initial state may not be undefined, but can be null.')}))}(r)}catch(e){u=e}return function(e,t){if(void 0===e&&(e={}),u)throw u;for(var n=!1,o={},i=0;i<c.length;i++){var f=c[i],s=e[f],d=(0,r[f])(s,t);if(void 0===d){var l=a(f,t);throw new Error(l)}o[f]=d,n=n||d!==s}return n?o:e}}function c(e,t){return function(){return t(e.apply(this,arguments))}}function f(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function s(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){f(e,t,r[t])}))}return e}function d(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return 0===t.length?function(e){return e}:1===t.length?t[0]:t.reduce((function(e,t){return function(){return e(t.apply(void 0,arguments))}}))}function l(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return function(e){return function(){var r=e.apply(void 0,arguments),n=function(){throw new Error("Dispatching while constructing your middleware is not allowed. Other middleware would not be applied to this dispatch.")},o={getState:r.getState,dispatch:function(){return n.apply(void 0,arguments)}},i=t.map((function(e){return e(o)}));return s({},r,{dispatch:n=d.apply(void 0,i)(r.dispatch)})}}}var p=d;function y(e,t){return e===t}function h(e,t,r){if(null===t||null===r||t.length!==r.length)return!1;for(var n=t.length,o=0;o<n;o++)if(!e(t[o],r[o]))return!1;return!0}function v(e){var t=Array.isArray(e[0])?e[0]:e;if(!t.every((function(e){return"function"==typeof e}))){var r=t.map((function(e){return typeof e})).join(", ");throw new Error("Selector creators expect all input-selectors to be functions, instead received the following types: ["+r+"]")}return t}var b=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return function(){for(var t=arguments.length,n=Array(t),o=0;o<t;o++)n[o]=arguments[o];var i=0,a=n.pop(),u=v(n),c=e.apply(void 0,[function(){return i++,a.apply(null,arguments)}].concat(r)),f=e((function(){for(var e=[],t=u.length,r=0;r<t;r++)e.push(u[r].apply(null,arguments));return c.apply(null,e)}));return f.resultFunc=a,f.dependencies=u,f.recomputations=function(){return i},f.resetRecomputations=function(){return i=0},f}}((function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:y,r=null,n=null;return function(){return h(t,r,arguments)||(n=e.apply(null,arguments)),r=arguments,n}}));function w(){return(w=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}var g,m=function(e,t){return function(e,t){var r=p;t.__esModule=!0,t.composeWithDevTools="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__:function(){if(0!==arguments.length)return"object"==typeof arguments[0]?r:r.apply(null,arguments)},t.devToolsEnhancer="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__?window.__REDUX_DEVTOOLS_EXTENSION__:function(){return function(e){return e}}}(t={exports:{}},t.exports),t.exports}();(g=m)&&g.__esModule&&Object.prototype.hasOwnProperty.call(g,"default");var E=m.composeWithDevTools;function O(e){if("object"!=typeof e||null===e)return!1;for(var t=e;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function j(e){return function(t){var r=t.dispatch,n=t.getState;return function(t){return function(o){return"function"==typeof o?o(r,n,e):t(o)}}}}var S=j();function _(e){return null==e||"string"==typeof e||"boolean"==typeof e||"number"==typeof e||Array.isArray(e)||O(e)}function x(e,t,r,n,o){var i;if(void 0===t&&(t=[]),void 0===r&&(r=_),void 0===o&&(o=[]),!r(e))return{keyPath:t.join(".")||"<root>",value:e};if("object"!=typeof e||null===e)return!1;var a=null!=n?n(e):Object.entries(e),u=o.length>0,c=a,f=Array.isArray(c),s=0;for(c=f?c:c[Symbol.iterator]();;){var d;if(f){if(s>=c.length)break;d=c[s++]}else{if((s=c.next()).done)break;d=s.value}var l=d[1],p=t.concat(d[0]);if(!(u&&o.indexOf(p.join("."))>=0)){if(!r(l))return{keyPath:p.join("."),value:l};if("object"==typeof l&&(i=x(l,p,r,n,o)))return i}}return!1}function A(e){void 0===e&&(e={});var t=e.thunk,r=void 0===t||t,n=[];return r&&(function(e){return"boolean"==typeof e}(r)?n.push(S):n.push(S.withExtraArgument(r.extraArgument))),n}function T(e,t){function r(){if(t){var r=t.apply(void 0,arguments);if(!r)throw new Error("prepareAction did not return an object");return w({type:e,payload:r.payload},"meta"in r&&{meta:r.meta},{},"error"in r&&{error:r.error})}return{type:e,payload:arguments.length<=0?void 0:arguments[0]}}return r.toString=function(){return""+e},r.type=e,r.match=function(t){return t.type===e},r}function N(e){var t={},r={addCase:function(e,n){var o="string"==typeof e?e:e.type;if(o in t)throw new Error("addCase cannot be called with two reducers for the same action type");return t[o]=n,r}};return e(r),t}function P(e,t){var r="function"==typeof t?N(t):t;return function(t,n){void 0===t&&(t=e);var o=r[n.type];return void 0===o?t:o(t,n)}}S.withExtraArgument=j,e.__DO_NOT_USE__ActionTypes=n,e.applyMiddleware=l,e.bindActionCreators=function(e,t){if("function"==typeof e)return c(e,t);if("object"!=typeof e||null===e)throw new Error("bindActionCreators expected an object or a function, instead received "+(null===e?"null":typeof e)+'. Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?');for(var r=Object.keys(e),n={},o=0;o<r.length;o++){var i=r[o],a=e[i];"function"==typeof a&&(n[i]=c(a,t))}return n},e.combineReducers=u,e.compose=d,e.configureStore=function(e){var t,r=e||{},n=r.reducer,o=void 0===n?void 0:n,a=r.middleware,c=void 0===a?A():a,f=r.devTools,s=void 0===f||f,p=r.preloadedState,y=void 0===p?void 0:p,h=r.enhancers,v=void 0===h?void 0:h;if("function"==typeof o)t=o;else{if(!O(o))throw new Error('"reducer" is a required argument, and must be a function or an object of functions that can be passed to combineReducers');t=u(o)}var b=l.apply(void 0,c),g=d;s&&(g=E(w({trace:!1},"object"==typeof s&&s)));var m=[b];return Array.isArray(v)?m=[b].concat(v):"function"==typeof v&&(m=v(m)),i(t,y,g.apply(void 0,m))},e.createAction=T,e.createReducer=P,e.createSelector=b,e.createSerializableStateInvariantMiddleware=function(e){void 0===e&&(e={});var t=e.isSerializable,r=void 0===t?_:t,n=e.getEntries,o=e.ignoredActions,i=void 0===o?[]:o,a=e.ignoredPaths,u=void 0===a?[]:a;return function(e){return function(t){return function(o){if(i.length&&-1!==i.indexOf(o.type))return t(o);var a=x(o,[],r,n);a&&console.error("A non-serializable value was detected in an action, in the path: `"+a.keyPath+"`. Value:",a.value,"\nTake a look at the logic that dispatched this action: ",o,"\n(See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)");var c=t(o),f=x(e.getState(),[],r,n,u);return f&&console.error("A non-serializable value was detected in the state, in the path: `"+f.keyPath+"`. Value:",f.value,"\nTake a look at the reducer(s) handling this action type: "+o.type+".\n(See https://redux.js.org/faq/organizing-state#can-i-put-functions-promises-or-other-non-serializable-items-in-my-store-state)"),c}}}},e.createSlice=function(e){var t=e.name,r=e.initialState;if(!t)throw new Error("`name` is a required option for createSlice");var n=e.reducers||{},o=void 0===e.extraReducers?{}:"function"==typeof e.extraReducers?N(e.extraReducers):e.extraReducers,i=Object.keys(n),a={},u={},c={};i.forEach((function(e){var r,o,i=n[e],f=t+"/"+e;"reducer"in i?(r=i.reducer,o=i.prepare):r=i,a[e]=r,u[f]=r,c[e]=o?T(f,o):T(f)}));var f=P(r,w({},o,{},u));return{name:t,reducer:f,actions:c,caseReducers:a}},e.createStore=i,e.findNonSerializableValue=x,e.getDefaultMiddleware=A,e.getType=function(e){return""+e},e.isPlain=_}));
//# sourceMappingURL=redux-toolkit.umd.min.js.map