6
6
* Configure middleware
7
7
* @type {import('@gasket/core').HookHandler<'middleware'> }
8
8
*/
9
- module . exports = function middlewareHook ( gasket ) {
9
+ module . exports = async function middlewareHook ( gasket ) {
10
10
const { redux : reduxConfig = { } } = gasket . config ;
11
11
12
12
if ( ! reduxConfig . makeStore ) {
@@ -15,21 +15,29 @@ module.exports = function middlewareHook(gasket) {
15
15
) ;
16
16
}
17
17
18
+ const mod = await import ( reduxConfig . makeStore ) ;
18
19
/** @type {import('@gasket/redux').MakeStoreFn } */
19
- const makeStore = require ( reduxConfig . makeStore ) ;
20
+ const makeStore = mod . makeStore ?? mod . default ;
20
21
21
22
/**
22
23
* Middleware to attach the redux store to the req object for use in other
23
24
* middleware
24
25
* @type {import('./index').reduxMiddleware }
25
26
*/
26
27
return async function middleware ( req , res , next ) {
27
- const initState = await gasket . execWaterfall (
28
+ const context = { req, res } ;
29
+ let initState = reduxConfig . initState || { } ;
30
+
31
+ await gasket . execApply (
28
32
'initReduxState' ,
29
- reduxConfig . initState || { } ,
30
- {
31
- req,
32
- res
33
+ async ( plugin , handler ) => {
34
+ const name = plugin ? plugin . name || 'unnamed plugin' : 'app lifecycles' ;
35
+ gasket . logger . warn (
36
+ `DEPRECATED \`initReduxState\` lifecycle in ${ name } will not be support in future major release.`
37
+ ) ;
38
+
39
+ // eslint-disable-next-line require-atomic-updates
40
+ initState = await handler ( initState , context ) ;
33
41
}
34
42
) ;
35
43
@@ -38,7 +46,17 @@ module.exports = function middlewareHook(gasket) {
38
46
req
39
47
} ) ;
40
48
41
- await gasket . exec ( 'initReduxStore' , store , { req, res } ) ;
49
+ await gasket . execApply (
50
+ 'initReduxStore' ,
51
+ async ( plugin , handler ) => {
52
+ const name = plugin ? plugin . name || 'unnamed plugin' : 'app lifecycles' ;
53
+ gasket . logger . warn (
54
+ `DEPRECATED \`initReduxStore\` lifecycle in ${ name } will not be support in future major release.`
55
+ ) ;
56
+
57
+ handler ( store , context ) ;
58
+ }
59
+ ) ;
42
60
43
61
// eslint-disable-next-line require-atomic-updates
44
62
req . store = store ;
0 commit comments