1- import Global from './global'
21import { setPartialState , timeout , getCache } from './helper'
32// -- Middlewares --
43
5- const tryCatch : Middleware < { } > = async ( context , restMiddlewares ) => {
4+ const tryCatch : Middleware = async ( context , restMiddlewares ) => {
65 const { next } = context
76 await next ( restMiddlewares ) . catch ( ( e : any ) => console . log ( e ) )
87}
98
10- const getNewState : Middleware < { } > = async ( context , restMiddlewares ) => {
11- const { action, modelName, consumerActions, params, next } = context
9+ const getNewState : Middleware = async ( context , restMiddlewares ) => {
10+ const { action, modelName, consumerActions, params, next, Global } = context
1211 context . newState =
1312 ( await action (
1413 Global . State [ modelName ] ,
@@ -24,6 +23,7 @@ const getNewStateWithCache = (maxTime: number = 5000): Middleware => async (
2423) => {
2524 const {
2625 action,
26+ Global,
2727 modelName,
2828 consumerActions,
2929 params,
@@ -51,22 +51,23 @@ const setNewState: Middleware = async (context, restMiddlewares) => {
5151}
5252
5353const stateUpdater : Middleware = async ( context , restMiddlewares ) => {
54- const { modelName, next } = context
54+ const { modelName, next, Global } = context
5555 context . type === 'function' &&
5656 context . setState &&
5757 context . setState ( Global . State [ modelName ] )
5858 await next ( restMiddlewares )
5959}
6060
6161const subscription : Middleware = async ( context , restMiddlewares ) => {
62- const { modelName, actionName, next } = context
62+ const { modelName, actionName, next, Global } = context
6363 if ( Global . subscriptions [ `${ modelName } _${ actionName } ` ] ) {
6464 Global . subscriptions [ `${ modelName } _${ actionName } ` ] ( )
6565 }
6666 await next ( restMiddlewares )
6767}
6868
6969const consoleDebugger : Middleware = async ( context , restMiddlewares ) => {
70+ const { Global } = context
7071 console . group (
7172 `%c ${
7273 context . modelName
@@ -94,6 +95,7 @@ const consoleDebugger: Middleware = async (context, restMiddlewares) => {
9495}
9596
9697const devToolsListener : Middleware = async ( context , restMiddlewares ) => {
98+ const { Global } = context
9799 await context . next ( restMiddlewares )
98100 if ( Global . withDevTools ) {
99101 Global . devTools . send (
@@ -103,8 +105,8 @@ const devToolsListener: Middleware = async (context, restMiddlewares) => {
103105 }
104106}
105107
106- const communicator : Middleware < { } > = async ( context , restMiddlewares ) => {
107- const { modelName, next, actionName } = context
108+ const communicator : Middleware = async ( context , restMiddlewares ) => {
109+ const { modelName, next, actionName, Global } = context
108110 if ( Global . Setter . classSetter ) {
109111 Global . Setter . classSetter ( Global . State )
110112 }
0 commit comments