MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / createStore

Function createStore

code/redux/public/app.js:21460–21670  ·  view source on GitHub ↗
(reducer, preloadedState, enhancer)

Source from the content-addressed store, hash-verified

21458 * and subscribe to changes.
21459 */
21460};function createStore(reducer, preloadedState, enhancer) {
21461 var _ref2;
21462
21463 if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') {
21464 enhancer = preloadedState;
21465 preloadedState = undefined;
21466 }
21467
21468 if (typeof enhancer !== 'undefined') {
21469 if (typeof enhancer !== 'function') {
21470 throw new Error('Expected the enhancer to be a function.');
21471 }
21472
21473 return enhancer(createStore)(reducer, preloadedState);
21474 }
21475
21476 if (typeof reducer !== 'function') {
21477 throw new Error('Expected the reducer to be a function.');
21478 }
21479
21480 var currentReducer = reducer;
21481 var currentState = preloadedState;
21482 var currentListeners = [];
21483 var nextListeners = currentListeners;
21484 var isDispatching = false;
21485
21486 function ensureCanMutateNextListeners() {
21487 if (nextListeners === currentListeners) {
21488 nextListeners = currentListeners.slice();
21489 }
21490 }
21491
21492 /**
21493 * Reads the state tree managed by the store.
21494 *
21495 * @returns {any} The current state tree of your application.
21496 */
21497 function getState() {
21498 return currentState;
21499 }
21500
21501 /**
21502 * Adds a change listener. It will be called any time an action is dispatched,
21503 * and some part of the state tree may potentially have changed. You may then
21504 * call `getState()` to read the current state tree inside the callback.
21505 *
21506 * You may call `dispatch()` from a change listener, with the following
21507 * caveats:
21508 *
21509 * 1. The subscriptions are snapshotted just before every `dispatch()` call.
21510 * If you subscribe or unsubscribe while the listeners are being invoked, this
21511 * will not have any effect on the `dispatch()` that is currently in progress.
21512 * However, the next `dispatch()` call, whether nested or not, will use a more
21513 * recent snapshot of the subscription list.
21514 *
21515 * 2. The listener should not expect to see all state changes, as the state
21516 * might have been updated multiple times during a nested `dispatch()` before
21517 * the listener is called. It is, however, guaranteed that all subscribers

Callers 2

app.jsxFile · 0.90
applyMiddlewareFunction · 0.85

Calls 1

dispatchFunction · 0.70

Tested by

no test coverage detected