(hooksAndOpts = {}, createOpts = {})
| 32 | * @param createOpts |
| 33 | */ |
| 34 | export 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, |
no test coverage detected
searching dependent graphs…