source: node_modules/redux/dist/cjs/redux.cjs

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 17.7 KB
Line 
1"use strict";
2var __defProp = Object.defineProperty;
3var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4var __getOwnPropNames = Object.getOwnPropertyNames;
5var __hasOwnProp = Object.prototype.hasOwnProperty;
6var __export = (target, all) => {
7 for (var name in all)
8 __defProp(target, name, { get: all[name], enumerable: true });
9};
10var __copyProps = (to, from, except, desc) => {
11 if (from && typeof from === "object" || typeof from === "function") {
12 for (let key of __getOwnPropNames(from))
13 if (!__hasOwnProp.call(to, key) && key !== except)
14 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15 }
16 return to;
17};
18var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
20// src/index.ts
21var src_exports = {};
22__export(src_exports, {
23 __DO_NOT_USE__ActionTypes: () => actionTypes_default,
24 applyMiddleware: () => applyMiddleware,
25 bindActionCreators: () => bindActionCreators,
26 combineReducers: () => combineReducers,
27 compose: () => compose,
28 createStore: () => createStore,
29 isAction: () => isAction,
30 isPlainObject: () => isPlainObject,
31 legacy_createStore: () => legacy_createStore
32});
33module.exports = __toCommonJS(src_exports);
34
35// src/utils/formatProdErrorMessage.ts
36function formatProdErrorMessage(code) {
37 return `Minified Redux error #${code}; visit https://redux.js.org/Errors?code=${code} for the full message or use the non-minified dev environment for full errors. `;
38}
39
40// src/utils/symbol-observable.ts
41var $$observable = /* @__PURE__ */ (() => typeof Symbol === "function" && Symbol.observable || "@@observable")();
42var symbol_observable_default = $$observable;
43
44// src/utils/actionTypes.ts
45var randomString = () => Math.random().toString(36).substring(7).split("").join(".");
46var ActionTypes = {
47 INIT: `@@redux/INIT${/* @__PURE__ */ randomString()}`,
48 REPLACE: `@@redux/REPLACE${/* @__PURE__ */ randomString()}`,
49 PROBE_UNKNOWN_ACTION: () => `@@redux/PROBE_UNKNOWN_ACTION${randomString()}`
50};
51var actionTypes_default = ActionTypes;
52
53// src/utils/isPlainObject.ts
54function isPlainObject(obj) {
55 if (typeof obj !== "object" || obj === null)
56 return false;
57 let proto = obj;
58 while (Object.getPrototypeOf(proto) !== null) {
59 proto = Object.getPrototypeOf(proto);
60 }
61 return Object.getPrototypeOf(obj) === proto || Object.getPrototypeOf(obj) === null;
62}
63
64// src/utils/kindOf.ts
65function miniKindOf(val) {
66 if (val === void 0)
67 return "undefined";
68 if (val === null)
69 return "null";
70 const type = typeof val;
71 switch (type) {
72 case "boolean":
73 case "string":
74 case "number":
75 case "symbol":
76 case "function": {
77 return type;
78 }
79 }
80 if (Array.isArray(val))
81 return "array";
82 if (isDate(val))
83 return "date";
84 if (isError(val))
85 return "error";
86 const constructorName = ctorName(val);
87 switch (constructorName) {
88 case "Symbol":
89 case "Promise":
90 case "WeakMap":
91 case "WeakSet":
92 case "Map":
93 case "Set":
94 return constructorName;
95 }
96 return Object.prototype.toString.call(val).slice(8, -1).toLowerCase().replace(/\s/g, "");
97}
98function ctorName(val) {
99 return typeof val.constructor === "function" ? val.constructor.name : null;
100}
101function isError(val) {
102 return val instanceof Error || typeof val.message === "string" && val.constructor && typeof val.constructor.stackTraceLimit === "number";
103}
104function isDate(val) {
105 if (val instanceof Date)
106 return true;
107 return typeof val.toDateString === "function" && typeof val.getDate === "function" && typeof val.setDate === "function";
108}
109function kindOf(val) {
110 let typeOfVal = typeof val;
111 if (process.env.NODE_ENV !== "production") {
112 typeOfVal = miniKindOf(val);
113 }
114 return typeOfVal;
115}
116
117// src/createStore.ts
118function createStore(reducer, preloadedState, enhancer) {
119 if (typeof reducer !== "function") {
120 throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(2) : `Expected the root reducer to be a function. Instead, received: '${kindOf(reducer)}'`);
121 }
122 if (typeof preloadedState === "function" && typeof enhancer === "function" || typeof enhancer === "function" && typeof arguments[3] === "function") {
123 throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(0) : "It looks like you are passing several store enhancers to createStore(). This is not supported. Instead, compose them together to a single function. See https://redux.js.org/tutorials/fundamentals/part-4-store#creating-a-store-with-enhancers for an example.");
124 }
125 if (typeof preloadedState === "function" && typeof enhancer === "undefined") {
126 enhancer = preloadedState;
127 preloadedState = void 0;
128 }
129 if (typeof enhancer !== "undefined") {
130 if (typeof enhancer !== "function") {
131 throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(1) : `Expected the enhancer to be a function. Instead, received: '${kindOf(enhancer)}'`);
132 }
133 return enhancer(createStore)(reducer, preloadedState);
134 }
135 let currentReducer = reducer;
136 let currentState = preloadedState;
137 let currentListeners = /* @__PURE__ */ new Map();
138 let nextListeners = currentListeners;
139 let listenerIdCounter = 0;
140 let isDispatching = false;
141 function ensureCanMutateNextListeners() {
142 if (nextListeners === currentListeners) {
143 nextListeners = /* @__PURE__ */ new Map();
144 currentListeners.forEach((listener, key) => {
145 nextListeners.set(key, listener);
146 });
147 }
148 }
149 function getState() {
150 if (isDispatching) {
151 throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(3) : "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.");
152 }
153 return currentState;
154 }
155 function subscribe(listener) {
156 if (typeof listener !== "function") {
157 throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(4) : `Expected the listener to be a function. Instead, received: '${kindOf(listener)}'`);
158 }
159 if (isDispatching) {
160 throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(5) : "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/store#subscribelistener for more details.");
161 }
162 let isSubscribed = true;
163 ensureCanMutateNextListeners();
164 const listenerId = listenerIdCounter++;
165 nextListeners.set(listenerId, listener);
166 return function unsubscribe() {
167 if (!isSubscribed) {
168 return;
169 }
170 if (isDispatching) {
171 throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(6) : "You may not unsubscribe from a store listener while the reducer is executing. See https://redux.js.org/api/store#subscribelistener for more details.");
172 }
173 isSubscribed = false;
174 ensureCanMutateNextListeners();
175 nextListeners.delete(listenerId);
176 currentListeners = null;
177 };
178 }
179 function dispatch(action) {
180 if (!isPlainObject(action)) {
181 throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(7) : `Actions must be plain objects. Instead, the actual type was: '${kindOf(action)}'. You may need to add middleware to your store setup to handle dispatching other values, such as 'redux-thunk' to handle dispatching functions. See https://redux.js.org/tutorials/fundamentals/part-4-store#middleware and https://redux.js.org/tutorials/fundamentals/part-6-async-logic#using-the-redux-thunk-middleware for examples.`);
182 }
183 if (typeof action.type === "undefined") {
184 throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(8) : 'Actions may not have an undefined "type" property. You may have misspelled an action type string constant.');
185 }
186 if (typeof action.type !== "string") {
187 throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(17) : `Action "type" property must be a string. Instead, the actual type was: '${kindOf(action.type)}'. Value was: '${action.type}' (stringified)`);
188 }
189 if (isDispatching) {
190 throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(9) : "Reducers may not dispatch actions.");
191 }
192 try {
193 isDispatching = true;
194 currentState = currentReducer(currentState, action);
195 } finally {
196 isDispatching = false;
197 }
198 const listeners = currentListeners = nextListeners;
199 listeners.forEach((listener) => {
200 listener();
201 });
202 return action;
203 }
204 function replaceReducer(nextReducer) {
205 if (typeof nextReducer !== "function") {
206 throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(10) : `Expected the nextReducer to be a function. Instead, received: '${kindOf(nextReducer)}`);
207 }
208 currentReducer = nextReducer;
209 dispatch({
210 type: actionTypes_default.REPLACE
211 });
212 }
213 function observable() {
214 const outerSubscribe = subscribe;
215 return {
216 /**
217 * The minimal observable subscription method.
218 * @param observer Any object that can be used as an observer.
219 * The observer object should have a `next` method.
220 * @returns An object with an `unsubscribe` method that can
221 * be used to unsubscribe the observable from the store, and prevent further
222 * emission of values from the observable.
223 */
224 subscribe(observer) {
225 if (typeof observer !== "object" || observer === null) {
226 throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(11) : `Expected the observer to be an object. Instead, received: '${kindOf(observer)}'`);
227 }
228 function observeState() {
229 const observerAsObserver = observer;
230 if (observerAsObserver.next) {
231 observerAsObserver.next(getState());
232 }
233 }
234 observeState();
235 const unsubscribe = outerSubscribe(observeState);
236 return {
237 unsubscribe
238 };
239 },
240 [symbol_observable_default]() {
241 return this;
242 }
243 };
244 }
245 dispatch({
246 type: actionTypes_default.INIT
247 });
248 const store = {
249 dispatch,
250 subscribe,
251 getState,
252 replaceReducer,
253 [symbol_observable_default]: observable
254 };
255 return store;
256}
257function legacy_createStore(reducer, preloadedState, enhancer) {
258 return createStore(reducer, preloadedState, enhancer);
259}
260
261// src/utils/warning.ts
262function warning(message) {
263 if (typeof console !== "undefined" && typeof console.error === "function") {
264 console.error(message);
265 }
266 try {
267 throw new Error(message);
268 } catch (e) {
269 }
270}
271
272// src/combineReducers.ts
273function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) {
274 const reducerKeys = Object.keys(reducers);
275 const argumentName = action && action.type === actionTypes_default.INIT ? "preloadedState argument passed to createStore" : "previous state received by the reducer";
276 if (reducerKeys.length === 0) {
277 return "Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.";
278 }
279 if (!isPlainObject(inputState)) {
280 return `The ${argumentName} has unexpected type of "${kindOf(inputState)}". Expected argument to be an object with the following keys: "${reducerKeys.join('", "')}"`;
281 }
282 const unexpectedKeys = Object.keys(inputState).filter((key) => !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key]);
283 unexpectedKeys.forEach((key) => {
284 unexpectedKeyCache[key] = true;
285 });
286 if (action && action.type === actionTypes_default.REPLACE)
287 return;
288 if (unexpectedKeys.length > 0) {
289 return `Unexpected ${unexpectedKeys.length > 1 ? "keys" : "key"} "${unexpectedKeys.join('", "')}" found in ${argumentName}. Expected to find one of the known reducer keys instead: "${reducerKeys.join('", "')}". Unexpected keys will be ignored.`;
290 }
291}
292function assertReducerShape(reducers) {
293 Object.keys(reducers).forEach((key) => {
294 const reducer = reducers[key];
295 const initialState = reducer(void 0, {
296 type: actionTypes_default.INIT
297 });
298 if (typeof initialState === "undefined") {
299 throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(12) : `The slice reducer for key "${key}" 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.`);
300 }
301 if (typeof reducer(void 0, {
302 type: actionTypes_default.PROBE_UNKNOWN_ACTION()
303 }) === "undefined") {
304 throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(13) : `The slice reducer for key "${key}" returned undefined when probed with a random type. Don't try to handle '${actionTypes_default.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.`);
305 }
306 });
307}
308function combineReducers(reducers) {
309 const reducerKeys = Object.keys(reducers);
310 const finalReducers = {};
311 for (let i = 0; i < reducerKeys.length; i++) {
312 const key = reducerKeys[i];
313 if (process.env.NODE_ENV !== "production") {
314 if (typeof reducers[key] === "undefined") {
315 warning(`No reducer provided for key "${key}"`);
316 }
317 }
318 if (typeof reducers[key] === "function") {
319 finalReducers[key] = reducers[key];
320 }
321 }
322 const finalReducerKeys = Object.keys(finalReducers);
323 let unexpectedKeyCache;
324 if (process.env.NODE_ENV !== "production") {
325 unexpectedKeyCache = {};
326 }
327 let shapeAssertionError;
328 try {
329 assertReducerShape(finalReducers);
330 } catch (e) {
331 shapeAssertionError = e;
332 }
333 return function combination(state = {}, action) {
334 if (shapeAssertionError) {
335 throw shapeAssertionError;
336 }
337 if (process.env.NODE_ENV !== "production") {
338 const warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache);
339 if (warningMessage) {
340 warning(warningMessage);
341 }
342 }
343 let hasChanged = false;
344 const nextState = {};
345 for (let i = 0; i < finalReducerKeys.length; i++) {
346 const key = finalReducerKeys[i];
347 const reducer = finalReducers[key];
348 const previousStateForKey = state[key];
349 const nextStateForKey = reducer(previousStateForKey, action);
350 if (typeof nextStateForKey === "undefined") {
351 const actionType = action && action.type;
352 throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(14) : `When called with an action of type ${actionType ? `"${String(actionType)}"` : "(unknown type)"}, the slice reducer for key "${key}" 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.`);
353 }
354 nextState[key] = nextStateForKey;
355 hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
356 }
357 hasChanged = hasChanged || finalReducerKeys.length !== Object.keys(state).length;
358 return hasChanged ? nextState : state;
359 };
360}
361
362// src/bindActionCreators.ts
363function bindActionCreator(actionCreator, dispatch) {
364 return function(...args) {
365 return dispatch(actionCreator.apply(this, args));
366 };
367}
368function bindActionCreators(actionCreators, dispatch) {
369 if (typeof actionCreators === "function") {
370 return bindActionCreator(actionCreators, dispatch);
371 }
372 if (typeof actionCreators !== "object" || actionCreators === null) {
373 throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(16) : `bindActionCreators expected an object or a function, but instead received: '${kindOf(actionCreators)}'. Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?`);
374 }
375 const boundActionCreators = {};
376 for (const key in actionCreators) {
377 const actionCreator = actionCreators[key];
378 if (typeof actionCreator === "function") {
379 boundActionCreators[key] = bindActionCreator(actionCreator, dispatch);
380 }
381 }
382 return boundActionCreators;
383}
384
385// src/compose.ts
386function compose(...funcs) {
387 if (funcs.length === 0) {
388 return (arg) => arg;
389 }
390 if (funcs.length === 1) {
391 return funcs[0];
392 }
393 return funcs.reduce((a, b) => (...args) => a(b(...args)));
394}
395
396// src/applyMiddleware.ts
397function applyMiddleware(...middlewares) {
398 return (createStore2) => (reducer, preloadedState) => {
399 const store = createStore2(reducer, preloadedState);
400 let dispatch = () => {
401 throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(15) : "Dispatching while constructing your middleware is not allowed. Other middleware would not be applied to this dispatch.");
402 };
403 const middlewareAPI = {
404 getState: store.getState,
405 dispatch: (action, ...args) => dispatch(action, ...args)
406 };
407 const chain = middlewares.map((middleware) => middleware(middlewareAPI));
408 dispatch = compose(...chain)(store.dispatch);
409 return {
410 ...store,
411 dispatch
412 };
413 };
414}
415
416// src/utils/isAction.ts
417function isAction(action) {
418 return isPlainObject(action) && "type" in action && typeof action.type === "string";
419}
420// Annotate the CommonJS export names for ESM import in node:
4210 && (module.exports = {
422 __DO_NOT_USE__ActionTypes,
423 applyMiddleware,
424 bindActionCreators,
425 combineReducers,
426 compose,
427 createStore,
428 isAction,
429 isPlainObject,
430 legacy_createStore
431});
432//# sourceMappingURL=redux.cjs.map
Note: See TracBrowser for help on using the repository browser.