Skip to content

Instantly share code, notes, and snippets.

@drskullster
Last active February 3, 2021 13:02

Revisions

  1. Jonathan Berger revised this gist Feb 3, 2021. 1 changed file with 2 additions and 17 deletions.
    19 changes: 2 additions & 17 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -27,13 +27,14 @@
    },
    forgotPassword: {
    on: {
    FORGOT_SUCCESS: 'success',
    SUCCESS: 'success',
    FORGOT_BACK: 'logIn'
    }
    },
    subscribe: {
    on: {
    SUCCESS: 'success',

    }
    },
    oauth: {
    @@ -42,25 +43,9 @@
    end: {
    type: 'final'
    },
    loading: {
    on: {
    RESOLVE: 'success',
    REJECT: 'failure'
    }
    },
    success: {
    type: 'final'
    },
    failure: {
    on: {
    RETRY: {
    target: 'loading',
    actions: assign({
    retries: (context, event) => context.retries + 1
    })
    }
    }
    }
    }
    });

  2. Jonathan Berger created this gist Feb 3, 2021.
    66 changes: 66 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@

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

    const authMachine = Machine({
    id: 'auth',
    initial: 'logIn',
    context: {
    retries: 0
    },
    states: {
    logIn: {
    on: {
    SUCCESS: 'end',
    FORGOTTEN: 'forgotPassword',
    SUBSCRIBE: 'subscribe',
    OAUTH_LOGIN: 'oauth'
    }
    },
    forgotPassword: {
    on: {
    FORGOT_SUCCESS: 'success',
    FORGOT_BACK: 'logIn'
    }
    },
    subscribe: {
    on: {
    SUCCESS: 'success',
    }
    },
    oauth: {
    SUCCESS: 'success'
    },
    end: {
    type: 'final'
    },
    loading: {
    on: {
    RESOLVE: 'success',
    REJECT: 'failure'
    }
    },
    success: {
    type: 'final'
    },
    failure: {
    on: {
    RETRY: {
    target: 'loading',
    actions: assign({
    retries: (context, event) => context.retries + 1
    })
    }
    }
    }
    }
    });