Merge branch 'deploy-prep'

main v5.0.0
Yanick Champoux 2023-05-04 14:52:15 -04:00
commit 3680f2b289
6 changed files with 62 additions and 38 deletions

1
.gitignore vendored
View File

@ -10,3 +10,4 @@ yarn-error.log
GPUCache/ GPUCache/
updux-2.0.0.tgz updux-2.0.0.tgz
pnpm-lock.yaml pnpm-lock.yaml
updux-5.0.0.tgz

View File

@ -1,18 +1,28 @@
*.test.* dist/**/*.test.js
test.*
docs docs
.eslint*
GPUCache/
node_modules/ node_modules/
tsconfig.tsbuildinfo
**/*.orig
dist
package-lock.json
yarn.lock
.nyc_output/ .nyc_output/
**/*.orig
out/
package-lock.json
pnpm-debug.log pnpm-debug.log
pnpm-lock.yaml pnpm-lock.yaml
yarn-error.log .pre-commit*
GPUCache/ .prettier*
updux-2.0.0.tgz
.travis.yml
.prettierignore .prettierignore
src/
Taskfile.yaml
*.test.*
test.*
TODO
tools/gen_sidebar.pl tools/gen_sidebar.pl
.travis.yml
tsconfig.json
tsconfig.tsbuildinfo
updux-2.0.0.tgz
updux-*.tgz
vitest.config.js
yarn-error.log
yarn.lock

View File

@ -9,13 +9,13 @@
"updeep": "^1.2.1" "updeep": "^1.2.1"
}, },
"license": "MIT", "license": "MIT",
"main": "src/index.js", "module": "dist/index.js",
"name": "updux", "name": "updux",
"description": "Updeep-friendly Redux helper framework", "description": "Updeep-friendly Redux helper framework",
"scripts": { "scripts": {
"docsify:serve": "docsify serve docs" "docsify:serve": "docsify serve docs"
}, },
"version": "4.0.0", "version": "5.0.0",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/yanick/updux.git" "url": "git+https://github.com/yanick/updux.git"

View File

@ -45,10 +45,10 @@ type ResolveAction<
? ActionArg ? ActionArg
: ActionArg extends (...args: any) => any : ActionArg extends (...args: any) => any
? ActionCreatorWithPreparedPayload< ? ActionCreatorWithPreparedPayload<
Parameters<ActionArg>, Parameters<ActionArg>,
ReturnType<ActionArg>, ReturnType<ActionArg>,
ActionType ActionType
> >
: ActionCreatorWithoutPayload<ActionType>; : ActionCreatorWithoutPayload<ActionType>;
type ResolveActions< type ResolveActions<
@ -56,10 +56,10 @@ type ResolveActions<
[key: string]: any; [key: string]: any;
}, },
> = { > = {
[ActionType in keyof A]: ActionType extends string [ActionType in keyof A]: ActionType extends string
? ResolveAction<ActionType, A[ActionType]> ? ResolveAction<ActionType, A[ActionType]>
: never; : never;
}; };
type Reaction<S = any, M extends MiddlewareAPI = MiddlewareAPI> = ( type Reaction<S = any, M extends MiddlewareAPI = MiddlewareAPI> = (
api: M, api: M,
@ -311,31 +311,44 @@ export default class Updux<
this.#defaultMutation = { mutation, terminal }; this.#defaultMutation = { mutation, terminal };
} }
addEffect(actionCreator: addEffect(
AggregateActions<ResolveActions<T_LocalActions>, T_Subduxes>, actionCreator: AggregateActions<
effect: EffectMiddleware): EffectMiddleware; ResolveActions<T_LocalActions>,
addEffect(guardFunc: (action: T_Subduxes
AggregateActions<ResolveActions<T_LocalActions>, T_Subduxes>[keyof AggregateActions<ResolveActions<T_LocalActions>, T_Subduxes>]) => boolean, >,
effect: EffectMiddleware): EffectMiddleware; 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(effect: EffectMiddleware): EffectMiddleware;
addEffect(...args) { addEffect(...args) {
let effect; let effect;
if (args.length === 1) { if (args.length === 1) {
effect = args[0]; effect = args[0];
} } else {
else {
const [actionCreator, originalEffect] = args; const [actionCreator, originalEffect] = args;
const test = actionCreator.hasOwnProperty('match') ? const test = actionCreator.hasOwnProperty('match')
actionCreator.match : actionCreator; ? actionCreator.match
: actionCreator;
effect = (api) => next => { effect = (api) => (next) => {
const e = originalEffect(api)(next); const e = originalEffect(api)(next);
return action => { return (action) => {
const func = test(action) ? e : next; const func = test(action) ? e : next;
return func(action); return func(action);
} };
} };
} }
this.#localEffects.push(effect); this.#localEffects.push(effect);

View File

@ -122,12 +122,12 @@ test('addEffect with actionCreator', () => {
(api) => (next) => (action) => next(spy(action)), (api) => (next) => (action) => next(spy(action)),
); );
mw({})(next)(dux.actions.bar()); mw({} as any)(next)(dux.actions.bar());
expect(next).toHaveBeenCalled(); expect(next).toHaveBeenCalled();
expect(spy).not.toHaveBeenCalled(); expect(spy).not.toHaveBeenCalled();
next.mockReset(); next.mockReset();
mw({})(next)(dux.actions.foo()); mw({} as any)(next)(dux.actions.foo());
expect(next).toHaveBeenCalled(); expect(next).toHaveBeenCalled();
expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalled();
}); });
@ -148,12 +148,12 @@ test('addEffect with function', () => {
(api) => (next) => (action) => next(spy(action)), (api) => (next) => (action) => next(spy(action)),
); );
mw({})(next)(dux.actions.bar()); mw({} as any)(next)(dux.actions.bar());
expect(next).toHaveBeenCalled(); expect(next).toHaveBeenCalled();
expect(spy).not.toHaveBeenCalled(); expect(spy).not.toHaveBeenCalled();
next.mockReset(); next.mockReset();
mw({})(next)(dux.actions.foo()); mw({} as any)(next)(dux.actions.foo());
expect(next).toHaveBeenCalled(); expect(next).toHaveBeenCalled();
expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalled();
}); });

View File

@ -35,7 +35,7 @@ test('initialState to createStore', () => {
}); });
expect( expect(
dux.createStore({ initialState: { a: 3, b: 4 } }).getState(), dux.createStore({ preloadedState: { a: 3, b: 4 } }).getState(),
).toEqual({ ).toEqual({
a: 3, a: 3,
b: 4, b: 4,