UNPKG

829 BJavaScriptView Raw
1export class RouterDispatcherService {
2 constructor(store) {
3 this.store = store;
4 }
5 dispatchFromMeta(meta) {
6 if (!meta || !this.store) {
7 return false;
8 }
9 Object.keys(meta).forEach((key) => {
10 this.dispatch(key, meta[key]);
11 });
12 return true;
13 }
14 dispatch(type, payload) {
15 return this.store.dispatch(type, payload);
16 }
17}
18export const registerActionDispatcher = (router, store) => {
19 const dispatcherService = new RouterDispatcherService(store);
20 router.beforeResolve((to, _from, _next) => {
21 const route = router.getRoute(to);
22 if (route && route.meta && route.meta.store) {
23 dispatcherService.dispatchFromMeta(route.meta.store);
24 }
25 });
26};
27//# sourceMappingURL=router-dispatcher-service.js.map
\No newline at end of file