initial state and subduxes tests are passing

This commit is contained in:
Yanick Champoux 2023-03-07 11:53:44 -05:00
parent e9778f98e8
commit 042f5b8f13
2 changed files with 15 additions and 6 deletions

View File

@ -20,7 +20,16 @@ import { AggregateActions, Dux, UnionToIntersection } from './types.js';
import { buildActions } from './buildActions.js';
import { buildInitial } from './buildInitial.js';
type AggregateState<L> = L;
type SubduxState<S> = 'initial' extends keyof S ? S['initial'] : {};
type AggregateState<LOCAL, SUBDUXES extends Record<any, any>> = LOCAL &
(keyof SUBDUXES extends never
? {}
: {
[Slice in keyof SUBDUXES]: Slice extends string
? SubduxState<SUBDUXES[Slice]>
: never;
});
type MyActionCreator = { type: string } & ((...args: any) => any);
@ -66,7 +75,7 @@ export default class Updux<
#localActions: T_LocalActions;
#localMutations: Record<
string,
Mutation<ActionCreator<any>, AggregateState<T_LocalState>>
Mutation<ActionCreator<any>, AggregateState<T_LocalState, SUBDUXES>>
> = {};
#subduxes: SUBDUXES;
@ -74,7 +83,7 @@ export default class Updux<
#actions: AggregateActions<ResolveActions<T_LocalActions>, SUBDUXES>;
#initial: any;
#initial: AggregateState<T_LocalState, SUBDUXES>;
constructor(
config: Partial<{
@ -119,7 +128,7 @@ export default class Updux<
// TODO force the actionCreator to be one of the actions?
mutation<A extends ActionCreator<any>>(
actionCreator: A,
mutation: Mutation<A, AggregateState<T_LocalState>>,
mutation: Mutation<A, AggregateState<T_LocalState, SUBDUXES>>,
) {
this.#localMutations[(actionCreator as any).type] = mutation;
}

View File

@ -49,7 +49,7 @@ test('single dux', () => {
});
// TODO add 'check for no todo eslint rule'
test.only('initial value', () => {
test('initial value', () => {
expect(foo.initial).toEqual({
root: 'abc',
bar: 123,
@ -78,7 +78,7 @@ test('no initial for subdux', () => {
expect(dux.initial).toEqual({ bar: {}, baz: 'potato' });
});
test('splat initial', async () => {
test.todo('splat initial', async () => {
const bar = new Updux({
initial: { id: 0 },
});