diff --git a/.gitignore b/.gitignore index 31e46d1..6817bbb 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ yarn-error.log GPUCache/ updux-2.0.0.tgz pnpm-lock.yaml +updux-5.0.0.tgz diff --git a/.npmignore b/.npmignore index 09420ec..fd693ab 100644 --- a/.npmignore +++ b/.npmignore @@ -1,18 +1,28 @@ -*.test.* -test.* +dist/**/*.test.js docs +.eslint* +GPUCache/ node_modules/ -tsconfig.tsbuildinfo -**/*.orig -dist -package-lock.json -yarn.lock .nyc_output/ +**/*.orig +out/ +package-lock.json pnpm-debug.log pnpm-lock.yaml -yarn-error.log -GPUCache/ -updux-2.0.0.tgz -.travis.yml +.pre-commit* +.prettier* .prettierignore +src/ +Taskfile.yaml +*.test.* +test.* +TODO 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 diff --git a/package.json b/package.json index ea2b77c..e323dde 100644 --- a/package.json +++ b/package.json @@ -9,13 +9,13 @@ "updeep": "^1.2.1" }, "license": "MIT", - "main": "src/index.js", + "module": "dist/index.js", "name": "updux", "description": "Updeep-friendly Redux helper framework", "scripts": { "docsify:serve": "docsify serve docs" }, - "version": "4.0.0", + "version": "5.0.0", "repository": { "type": "git", "url": "git+https://github.com/yanick/updux.git" diff --git a/src/Updux.ts b/src/Updux.ts index 99be92a..1c0f1c5 100644 --- a/src/Updux.ts +++ b/src/Updux.ts @@ -45,10 +45,10 @@ type ResolveAction< ? ActionArg : ActionArg extends (...args: any) => any ? ActionCreatorWithPreparedPayload< - Parameters, - ReturnType, - ActionType - > + Parameters, + ReturnType, + ActionType + > : ActionCreatorWithoutPayload; 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 : never; - }; +}; type Reaction = ( api: M, @@ -311,31 +311,44 @@ export default class Updux< this.#defaultMutation = { mutation, terminal }; } - addEffect(actionCreator: - AggregateActions, T_Subduxes>, - effect: EffectMiddleware): EffectMiddleware; - addEffect(guardFunc: (action: - AggregateActions, T_Subduxes>[keyof AggregateActions, T_Subduxes>]) => boolean, - effect: EffectMiddleware): EffectMiddleware; + addEffect( + actionCreator: AggregateActions< + ResolveActions, + T_Subduxes + >, + effect: EffectMiddleware, + ): EffectMiddleware; + addEffect( + guardFunc: ( + action: AggregateActions< + ResolveActions, + T_Subduxes + >[keyof AggregateActions< + ResolveActions, + 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); diff --git a/src/effects.test.ts b/src/effects.test.ts index 41e63ae..8dcbf22 100644 --- a/src/effects.test.ts +++ b/src/effects.test.ts @@ -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(); }); diff --git a/src/initial.test.ts b/src/initial.test.ts index 5dc76b2..5b2145d 100644 --- a/src/initial.test.ts +++ b/src/initial.test.ts @@ -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,