MCPcopy
hub / github.com/dvajs/dva / create

Function create

packages/dva-core/src/index.js:34–279  ·  view source on GitHub ↗
(hooksAndOpts = {}, createOpts = {})

Source from the content-addressed store, hash-verified

32 * @param createOpts
33 */
34export function create(hooksAndOpts = {}, createOpts = {}) {
35 const { initialReducer, setupApp = noop } = createOpts;
36
37 const plugin = new Plugin();
38 plugin.use(filterHooks(hooksAndOpts));
39
40 const app = {
41 _models: [prefixNamespace({ ...dvaModel })],
42 _store: null,
43 _plugin: plugin,
44 use: plugin.use.bind(plugin),
45 model,
46 start,
47 };
48 return app;
49
50 /**
51 * Register model before app is started.
52 *
53 * @param m {Object} model to register
54 */
55 function model(m) {
56 if (process.env.NODE_ENV !== 'production') {
57 checkModel(m, app._models);
58 }
59 const prefixedModel = prefixNamespace({ ...m });
60 app._models.push(prefixedModel);
61 return prefixedModel;
62 }
63
64 /**
65 * Inject model after app is started.
66 *
67 * @param createReducer
68 * @param onError
69 * @param unlisteners
70 * @param m
71 */
72 function injectModel(createReducer, onError, unlisteners, m) {
73 m = model(m);
74
75 const store = app._store;
76 store.asyncReducers[m.namespace] = getReducer(
77 m.reducers,
78 m.state,
79 plugin._handleActions
80 );
81 store.replaceReducer(createReducer());
82 if (m.effects) {
83 store.runSaga(
84 app._getSaga(m.effects, m, onError, plugin.get('onEffect'))
85 );
86 }
87 if (m.subscriptions) {
88 unlisteners[m.namespace] = runSubscription(
89 m.subscriptions,
90 m,
91 app,

Callers 7

effects.test.jsFile · 0.90
model.test.jsFile · 0.90
checkModel.test.jsFile · 0.90
reducers.test.jsFile · 0.90

Calls 3

useMethod · 0.95
filterHooksFunction · 0.90
prefixNamespaceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…