Last active
August 16, 2021 08:51
-
-
Save neeharv/3d4ee2cceb29287a3a5208c64cf66adf to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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 characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const fetchMachine = Machine({ | |
id: 'fetch', | |
initial: 'no_data', | |
states: { | |
no_data: { | |
// this is fresh app launch | |
// and initial launch after | |
// install, because we don't | |
// persist data, we only cache | |
// it in session / in memory | |
on: { | |
FETCH: 'loading' | |
} | |
}, | |
loading: { | |
on: { | |
SUCCESS: 'success', | |
DEFAULT: 'check_internet', | |
} | |
}, | |
success: { | |
on: { | |
// this is checking local data | |
NO_USER_OR_UPI_PROFILE: 'display_link_account', | |
NO_DEFAULT_ACCOUNT: 'display_activate_upi', | |
ALL_DATA: 'display_qr', | |
} | |
}, | |
display_link_account: { | |
// this is calling profile | |
// mehtods from MT | |
on: { | |
REFRESH_SUCCESS: 'success', | |
REFRESH_DEFAULT: 'got_default_data' | |
// REFRESH_FAILURE_AND_INTERNET: 'show_qr_generic_error', | |
// REFRESH_FAILURE_AND_NO_INTERNET: 'check_internet', | |
}, | |
type: 'final' | |
}, | |
display_activate_upi: { | |
// this is calling profile | |
// mehtods from MT | |
on: { | |
REFRESH_SUCCESS: 'success', | |
REFRESH_DEFAULT: 'got_default_data' | |
// REFRESH_FAILURE_AND_INTERNET: 'show_qr_generic_error', | |
// REFRESH_FAILURE_AND_NO_INTERNET: 'check_internet' | |
}, | |
type: 'final' | |
}, | |
display_qr: { | |
// refresh method here | |
// means fetchQR method | |
// from MT | |
on: { | |
REFRESH_SUCCESS_AND_INTERNET: 'success', | |
REFRESH_SUCCESS_AND_NO_INTERNET: | |
'display_qr', | |
REFRESH_FAILURE: 'got_default_data' | |
}, | |
type: 'final' | |
}, | |
got_default_data: { | |
on: { | |
NO_INTERNET: 'check_internet', | |
INTERNET: 'show_qr_generic_error', | |
}, | |
type: 'final' | |
}, | |
check_internet : { | |
on: { | |
REFRESH: 'loading' | |
}, | |
type: 'final' | |
}, | |
show_qr_generic_error : { | |
on: { | |
REFRESH: 'loading' | |
}, | |
type: 'final' | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment