Skip to content

Instantly share code, notes, and snippets.

@fauxparse
Last active January 17, 2023 20:36
Show Gist options
  • Select an option

  • Save fauxparse/b42dd4d0903984fe9845c1206265ef48 to your computer and use it in GitHub Desktop.

Select an option

Save fauxparse/b42dd4d0903984fe9845c1206265ef48 to your computer and use it in GitHub Desktop.

Revisions

  1. fauxparse revised this gist Jan 17, 2023. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions childContext.ts
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,24 @@
    const Machine = createMachine({
    context: {
    name: ''
    name: '',
    },
    schema: {
    context: {} as { name: string }
    context: {} as { name: string },
    },
    states: {
    A: {
    on: {
    NEXT: 'B'
    NEXT: 'B',
    },
    },
    B: {
    context: {
    count: 0,
    },
    schema: {} as { count: number }
    }
    schema: {
    context: {} as { count: number },
    },
    },
    },
    initial: 'A',
    });
  2. fauxparse created this gist Jan 17, 2023.
    32 changes: 32 additions & 0 deletions childContext.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    const Machine = createMachine({
    context: {
    name: ''
    },
    schema: {
    context: {} as { name: string }
    },
    states: {
    A: {
    on: {
    NEXT: 'B'
    },
    },
    B: {
    context: {
    count: 0,
    },
    schema: {} as { count: number }
    }
    },
    initial: 'A',
    });

    // ...

    const service = interpret(Machine);

    service.state.context // { name: '' }

    service.send('NEXT')

    service.state.context // { name: '', count: 0 }