Skip to content

Instantly share code, notes, and snippets.

@tmbtech
Created August 28, 2019 18:29
Show Gist options
  • Select an option

  • Save tmbtech/3b606eba3faa1c268d0ca681e6bae372 to your computer and use it in GitHub Desktop.

Select an option

Save tmbtech/3b606eba3faa1c268d0ca681e6bae372 to your computer and use it in GitHub Desktop.

Revisions

  1. tmbtech created this gist Aug 28, 2019.
    70 changes: 70 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,70 @@

    // Available variables:
    // - Machine
    // - interpret
    // - assign
    // - send
    // - sendParent
    // - spawn
    // - raise
    // - actions
    // - XState (all XState exports)

    const fetchMachine = Machine({
    id: 'createUser_mergeBD',
    context: {
    username: undefined,
    isPhoneVerified: undefined,
    mergeToken: undefined,
    },
    initial: 'idle',
    states: {
    idle: {
    on: {
    LOGIN_SUBMIT: 'pending',
    },
    },
    pending: {
    on: {
    SUCCESS: {
    target: 'checkVerification',
    actions: 'pending_success_actions',
    },
    },
    },
    checkVerification: {
    on: {
    '': [
    {
    target: 'isNotVerified',
    cond: context => !context.isPhoneVerified,
    },
    {
    target: 'isVerified',
    cond: context => !!context.isPhoneVerified,
    },
    ],
    },
    },
    isVerified: {
    on: {
    START_MIGRATION: {
    target: 'migrationRunning',
    },
    },
    },
    isNotVerified: {},
    migrationRunning: {
    on: {
    CHECK_STATUS: {
    target: 'migrationRunning',
    },
    MIGRATION_COMPLETE: {
    target: 'migrationComplete',
    },
    },
    },
    migrationComplete: {},
    },
    });