Created
October 14, 2019 11:59
-
-
Save Colubi/f836da412aea6cc0eb6081e6af6e8931 to your computer and use it in GitHub Desktop.
Revisions
-
Colubi created this gist
Oct 14, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,95 @@ Machine({ id: "optIn", type: "parallel", context: { optInState: "initial", optInRequest: { successState: "Success", }, }, states: { flow: { initial: "initial", states: { initial: { on: { START_OPTIN: [ { target: "progress", in: "#optIn.session.loggedIn", actions: ["assignOptInRequestParams"], }, { actions: ["assignOptInRequestParams", "displayLogin"], }, ], }, }, progress: { entry: "setLoading", invoke: { src: "requestOptIn", onDone: { target: "success", actions: assign({ optInState: (_, result) => result.data, }), }, onError: { target: "error", actions: assign({ optInState: (_, result) => result.data, }), }, }, }, success: { type: "final", entry: "onOptInSuccess", }, error: { type: "final", entry: "onOptInError", }, }, }, session: { initial: "notDetermined", states: { notDetermined: { on: { LOG_IN: { target: "loggedIn", }, LOG_OUT: { target: "loggedOut", }, }, }, loggedIn: { on: { LOG_OUT: { target: "loggedOut", }, }, }, loggedOut: { on: { LOG_IN: { target: "loggedIn", }, }, }, }, }, }, }, { actions: { assignOptInRequestParams: assign({ optInRequest: (_, event) => event.optInRequest, }), setLoading: assign({ optInState: "progress", }), }, });