1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
| const module = register(new RestaurantModule("restaurant", initialState));
// 注册module, "restaurant"- moduleName
// 初始化当前module的state到store中
export const restaurantActions = module.getActions();
// 获取当前module导出的所有sagaGenerator functions
export const RestaurantList = module.attachLifecycle(RestaurantComponent);
// 给RestaurantComponent注册当前module生命周期监听事件(onFocus/onDestory..., 一些api的异步操作)
// 先执行module当中的生命周期事件,再执行component中的
```markdown
function createApp(): App {
const eventLogger = new LoggerImpl();
const sagaMiddleware = createSagaMiddleware({
onError: (error, info) => captureError(error, "@@framework/detached-saga", {extraStacktrace: info.sagaStack}),
});
const store: Store<State> = createStore(rootReducer(), composeWithDevTools(applyMiddleware(sagaMiddleware)));
sagaMiddleware.run(function* () {
yield takeEvery("*", function* (action: Action<any>) {
const handler = app.actionHandlers[action.type];
if (handler) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
yield* executeAction(action.type, handler, ...action.payload);
}
});
});
return {
store,
sagaMiddleware,
actionHandlers: {},
logger: eventLogger,
loggerConfig: null,
*errorHandler() {},
};
}
|