add middleware wrapper
This commit is contained in:
parent
0b0ea7ea66
commit
7f1bcbddef
@ -22,9 +22,13 @@ export class Updux {
|
||||
#selectors = {};
|
||||
#effects = [];
|
||||
#localReactions = [];
|
||||
#middlewareWrapper;
|
||||
|
||||
constructor(config = {}) {
|
||||
this.#config = config;
|
||||
|
||||
this.#middlewareWrapper = config.middlewareWrapper;
|
||||
|
||||
this.#localInitial = config.initial;
|
||||
this.#subduxes = config.subduxes ?? {};
|
||||
|
||||
@ -148,7 +152,8 @@ export class Updux {
|
||||
this.#effects,
|
||||
this.actions,
|
||||
this.selectors,
|
||||
this.subduxes,
|
||||
this.#subduxes,
|
||||
this.#middlewareWrapper,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ export function augmentMiddlewareApi(api, actions, selectors) {
|
||||
}
|
||||
|
||||
const sliceMw = (slice, mw) => (api) => {
|
||||
const getSliceState = () => get(api.getState(), slice);
|
||||
const getSliceState = () => api.getState()[slice];
|
||||
return mw({ ...api, getState: getSliceState });
|
||||
};
|
||||
|
||||
@ -65,10 +65,11 @@ export function buildMiddleware(
|
||||
actions = {},
|
||||
selectors = {},
|
||||
subduxes = {},
|
||||
wrapper = undefined,
|
||||
) {
|
||||
let inner = R.compact(
|
||||
Object.entries(subduxes).map((slice, [{ middleware }]) =>
|
||||
slice !== '*' && middleware ? sliceMw(slice, middleware) : null,
|
||||
Object.entries(subduxes).map(([slice, { middleware }]) =>
|
||||
((slice !== '*' && middleware) ? sliceMw(slice, middleware) : null),
|
||||
),
|
||||
);
|
||||
|
||||
@ -78,5 +79,7 @@ export function buildMiddleware(
|
||||
|
||||
let mws = [...local, ...inner];
|
||||
|
||||
if( wrapper ) mws = wrapper(mws);
|
||||
|
||||
return composeMw(mws);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user