prettier
This commit is contained in:
parent
2e78e27bf6
commit
342d1b6f3a
53
src/Updux.ts
53
src/Updux.ts
@ -45,10 +45,10 @@ type ResolveAction<
|
||||
? ActionArg
|
||||
: ActionArg extends (...args: any) => any
|
||||
? ActionCreatorWithPreparedPayload<
|
||||
Parameters<ActionArg>,
|
||||
ReturnType<ActionArg>,
|
||||
ActionType
|
||||
>
|
||||
Parameters<ActionArg>,
|
||||
ReturnType<ActionArg>,
|
||||
ActionType
|
||||
>
|
||||
: ActionCreatorWithoutPayload<ActionType>;
|
||||
|
||||
type ResolveActions<
|
||||
@ -56,10 +56,10 @@ type ResolveActions<
|
||||
[key: string]: any;
|
||||
},
|
||||
> = {
|
||||
[ActionType in keyof A]: ActionType extends string
|
||||
[ActionType in keyof A]: ActionType extends string
|
||||
? ResolveAction<ActionType, A[ActionType]>
|
||||
: never;
|
||||
};
|
||||
};
|
||||
|
||||
type Reaction<S = any, M extends MiddlewareAPI = MiddlewareAPI> = (
|
||||
api: M,
|
||||
@ -311,31 +311,44 @@ export default class Updux<
|
||||
this.#defaultMutation = { mutation, terminal };
|
||||
}
|
||||
|
||||
addEffect(actionCreator:
|
||||
AggregateActions<ResolveActions<T_LocalActions>, T_Subduxes>,
|
||||
effect: EffectMiddleware): EffectMiddleware;
|
||||
addEffect(guardFunc: (action:
|
||||
AggregateActions<ResolveActions<T_LocalActions>, T_Subduxes>[keyof AggregateActions<ResolveActions<T_LocalActions>, T_Subduxes>]) => boolean,
|
||||
effect: EffectMiddleware): EffectMiddleware;
|
||||
addEffect(
|
||||
actionCreator: AggregateActions<
|
||||
ResolveActions<T_LocalActions>,
|
||||
T_Subduxes
|
||||
>,
|
||||
effect: EffectMiddleware,
|
||||
): EffectMiddleware;
|
||||
addEffect(
|
||||
guardFunc: (
|
||||
action: AggregateActions<
|
||||
ResolveActions<T_LocalActions>,
|
||||
T_Subduxes
|
||||
>[keyof AggregateActions<
|
||||
ResolveActions<T_LocalActions>,
|
||||
T_Subduxes
|
||||
>],
|
||||
) => boolean,
|
||||
effect: EffectMiddleware,
|
||||
): EffectMiddleware;
|
||||
addEffect(effect: EffectMiddleware): EffectMiddleware;
|
||||
addEffect(...args) {
|
||||
let effect;
|
||||
if (args.length === 1) {
|
||||
effect = args[0];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
const [actionCreator, originalEffect] = args;
|
||||
|
||||
const test = actionCreator.hasOwnProperty('match') ?
|
||||
actionCreator.match : actionCreator;
|
||||
const test = actionCreator.hasOwnProperty('match')
|
||||
? actionCreator.match
|
||||
: actionCreator;
|
||||
|
||||
effect = (api) => next => {
|
||||
effect = (api) => (next) => {
|
||||
const e = originalEffect(api)(next);
|
||||
return action => {
|
||||
return (action) => {
|
||||
const func = test(action) ? e : next;
|
||||
return func(action);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
this.#localEffects.push(effect);
|
||||
|
@ -122,12 +122,12 @@ test('addEffect with actionCreator', () => {
|
||||
(api) => (next) => (action) => next(spy(action)),
|
||||
);
|
||||
|
||||
mw({})(next)(dux.actions.bar());
|
||||
mw({} as any)(next)(dux.actions.bar());
|
||||
expect(next).toHaveBeenCalled();
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
|
||||
next.mockReset();
|
||||
mw({})(next)(dux.actions.foo());
|
||||
mw({} as any)(next)(dux.actions.foo());
|
||||
expect(next).toHaveBeenCalled();
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
@ -148,12 +148,12 @@ test('addEffect with function', () => {
|
||||
(api) => (next) => (action) => next(spy(action)),
|
||||
);
|
||||
|
||||
mw({})(next)(dux.actions.bar());
|
||||
mw({} as any)(next)(dux.actions.bar());
|
||||
expect(next).toHaveBeenCalled();
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
|
||||
next.mockReset();
|
||||
mw({})(next)(dux.actions.foo());
|
||||
mw({} as any)(next)(dux.actions.foo());
|
||||
expect(next).toHaveBeenCalled();
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
@ -35,7 +35,7 @@ test('initialState to createStore', () => {
|
||||
});
|
||||
|
||||
expect(
|
||||
dux.createStore({ initialState: { a: 3, b: 4 } }).getState(),
|
||||
dux.createStore({ preloadedState: { a: 3, b: 4 } }).getState(),
|
||||
).toEqual({
|
||||
a: 3,
|
||||
b: 4,
|
||||
|
Loading…
Reference in New Issue
Block a user