MCPcopy
hub / github.com/ctrlplusb/easy-peasy / createStore

Function createStore

src/create-store.js:20–183  ·  view source on GitHub ↗
(model, options = {})

Source from the content-addressed store, hash-verified

18import { createEffectsMiddleware } from './effects';
19
20export function createStore(model, options = {}) {
21 const modelClone = clone(model);
22 const {
23 compose,
24 devTools = process.env.NODE_ENV !== 'production',
25 disableImmer = false,
26 enhancers = [],
27 initialState = undefined,
28 injections = {},
29 middleware = [],
30 mockActions = false,
31 name: storeName = `EasyPeasyStore`,
32 version = 0,
33 reducerEnhancer = (rootReducer) => rootReducer,
34 } = options;
35
36 const bindReplaceState = (modelDef) => ({
37 ...modelDef,
38 ePRS: helpers.action((_, payload) => payload),
39 });
40
41 const _r = {};
42
43 let modeldef = bindReplaceState(modelClone);
44 let mockedActions = [];
45
46 const persistKey = (targetPath) =>
47 `[${storeName}][${version}]${
48 targetPath.length > 0 ? `[${targetPath.join('.')}]` : ''
49 }`;
50 const persistor = createPersistor(persistKey, _r);
51 const persistMiddleware = createPersistMiddleware(persistor, _r);
52
53 const replaceState = (nextState) => _r._i._aCD['@action.ePRS'](nextState);
54
55 const bindStoreInternals = (state = {}) => {
56 const data = extractDataFromModel(modeldef, state, injections, _r);
57 _r._i = {
58 ...data,
59 reducer: reducerEnhancer(
60 createReducer(disableImmer, data._aRD, data._cR, data._cP),
61 ),
62 };
63 };
64
65 const mockActionsMiddleware = () => () => (action) => {
66 if (action != null) {
67 mockedActions.push(action);
68 }
69 return undefined;
70 };
71
72 const devToolConfig = devTools === true ? {} : devTools;
73
74 const composeEnhancers =
75 compose ||
76 (devTools &&
77 typeof window !== 'undefined' &&

Callers 15

ProviderFunction · 0.90
useLocalStoreFunction · 0.90
generic.test.jsFile · 0.90
reducer.test.jsFile · 0.90
use-store.test.jsFile · 0.90
dev-tools.test.jsFile · 0.90
effect-on.test.jsFile · 0.90
sharedMakeStoreFunction · 0.90

Calls 11

cloneFunction · 0.90
createPersistorFunction · 0.90
createPersistMiddlewareFunction · 0.90
createListenerMiddlewareFunction · 0.90
createEffectsMiddlewareFunction · 0.90
bindReplaceStateFunction · 0.85
bindStoreInternalsFunction · 0.85
bindActionCreatorsFunction · 0.85
rebindStoreFunction · 0.85

Tested by 4

sharedMakeStoreFunction · 0.72
makeStoreFunction · 0.72
createPopulatedStoreFunction · 0.68
createPopulatedStoreFunction · 0.68