glorious noop

typescript
Yanick Champoux 2022-08-25 12:02:31 -04:00
parent 46b0565819
commit c609a19ef8
2 changed files with 5 additions and 3 deletions

View File

@ -25,6 +25,8 @@ export type DuxStateSubduxes<C extends {}> = keyof C extends never
? unknown
: { [K in keyof C]: StateOf<C[K]> };
type DuxAggregateState<TState,TSubduxes> = TState & DuxStateSubduxes<TSubduxes> ;
export class Updux<TState extends any = {}, TActions extends { [key: string]: ActionGenerator } = {}, TSubduxes = {}> {
#localInitial: any = {};
#subduxes;
@ -41,7 +43,7 @@ export class Updux<TState extends any = {}, TActions extends { [key: string]: Ac
return this.#actions;
}
get initial(): TState & DuxStateSubduxes<TSubduxes> {
get initial(): DuxAggregateState<TState,TSubduxes>{
if (Object.keys(this.#subduxes).length === 0) return this.#localInitial;
return Object.assign(
@ -52,6 +54,6 @@ export class Updux<TState extends any = {}, TActions extends { [key: string]: Ac
}
get reducer() {
return (state, action) => state;
return (state : DuxAggregateState<TState,TSubduxes>, _action : any) => state;
}
}

View File

@ -3,7 +3,7 @@ import { test, expect } from 'vitest';
import { Updux } from './Updux.js';
test('basic reducer', () => {
const dux = new Updux({});
const dux = new Updux({ initial: {a: 3} });
expect(dux.reducer).toBeTypeOf('function');