Skip to content

1.6.7

Choose a tag to compare

@ryupold ryupold released this 05 Dec 14:56
· 161 commits to main since this release
  • allow optional path objects for KeyPaths
    this eliminates the need to have non-nullable keys in sub-states that are addressed by KeyStateContext
    export type AppExampleState = {
        foobar: {
            example1: {
                app: { counter: number; text: string; },
            },
            example2?: {
                app: { counter: number; text: string; },
            },
            example3?: {
                app?: { counter: number; text: string; },
            },
        },
    };
    
    const state = createState<AppExampleState>({
        foobar: {
            example1: {
                app: {
                    counter: 0,
                    text: 'Hello, World!',
                },
            },
        }
    });
    
    const ctx1 = new KeyStateContext<typeof state, { counter: number; text: string; }>(state, "foobar.example1.app");
    const ctx2 = new KeyStateContext<typeof state, { counter: number; text: string; }>(state, "foobar.example2.app");
    const ctx3 = new KeyStateContext<typeof state, { counter: number; text: string; }>(state, "foobar.example3.app");
    in this example foobar.example1.app, foobar.example2.app and foobar.example3.app are the only valid keys