Last active
June 18, 2020 04:52
-
-
Save epan/94fd2a590b101ef92104e4c34d7bc6f6 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
// v5 | |
// existing behavior | |
// no network requests | |
// no saving local data | |
// no saving network response | |
// actions not optimized | |
const groupedStateMachineCurrentBehavior = Machine({ | |
id: 'addressManager', | |
context: { | |
location: undefined, | |
}, | |
initial: 'closed', | |
states: { | |
closed: { | |
id: 'closed', | |
on: { | |
OPEN: 'open' | |
} | |
}, | |
open: { | |
initial: 'addressList', | |
states: { | |
addressList: { | |
id: 'addressList', | |
initial: 'savedAddressesList', | |
states: { | |
savedAddressesList: { | |
id: 'savedAddressesList', | |
on: { | |
EDIT: '#editAddressExisting', | |
SELECT: { | |
target: '#loading', | |
actions: ['prevSavedAddressesList'] | |
}, | |
SEARCH: '#searchForNewAddress' | |
} | |
}, | |
searchForNewAddress: { | |
id: 'searchForNewAddress', | |
on: { | |
SELECT: '#editAddressNew', | |
CLOSE: '#savedAddressesList' | |
} | |
}, | |
}, | |
}, | |
editAddress: { | |
states: { | |
editAddressExisting: { | |
id: 'editAddressExisting', | |
on: { | |
ADJUST_PIN: '#adjustPinExisting', | |
CANCEL: '#addressList', | |
SUBMIT: { | |
target: '#loading', | |
actions: ['prevEditAddressExisting'] | |
} | |
} | |
}, | |
editAddressNew: { | |
id: 'editAddressNew', | |
on: { | |
ADJUST_PIN: '#adjustPinNew', | |
CANCEL: '#addressList', | |
SUBMIT: { | |
target: '#loading', | |
actions: ['prevEditAddressNew',] | |
} | |
} | |
}, | |
} | |
}, | |
adjustPin: { | |
states: { | |
adjustPinExisting: { | |
id: 'adjustPinExisting', | |
on: { | |
CANCEL: '#editAddressExisting', | |
SAVE: { | |
target: '#loading', | |
actions: ['prevAdjustPinExisting'] | |
} | |
} | |
}, | |
adjustPinNew: { | |
id: 'adjustPinNew', | |
on: { | |
CANCEL: '#editAddressNew', | |
SAVE: { | |
target: '#editAddressNew' | |
} | |
} | |
}, | |
} | |
}, | |
loading: { | |
id: 'loading', | |
on: { | |
RESOLVE: [ | |
{ target: '#closed', cond: (context) => context.prevLocation === 'editAddressNew' }, | |
{ target: '#addressList', cond: (context) => context.prevLocation === 'editAddressExisting' }, | |
{ target: '#closed', cond: (context) => context.prevLocation === 'savedAddressesList' }, | |
{ target: '#editAddressExisting', cond: (context) => context.prevLocation === 'adjustPinExisting' }, | |
], | |
REJECT: [ | |
{ target: '#editAddressNew', cond: (context) => context.prevLocation === 'editAddressNew' }, | |
{ target: '#editAddressExisting', cond: (context) => context.prevLocation === 'editAddressExisting' }, | |
{ target: '#savedAddressesList', cond: (context) => context.prevLocation === 'savedAddressesList' }, | |
{ target: '#adjustPinExisting', cond: (context) => context.prevLocation === 'adjustPinExisting' }, | |
] | |
}, | |
exit: 'clearPrevLocation' | |
} | |
}, | |
on: { | |
CLOSE: 'closed' | |
} | |
} | |
} | |
}, { | |
actions: { | |
updatePrevLocationWithCurrentState: assign({ | |
prevLocation: (_, event) => { | |
return event.location | |
} | |
}), | |
prevSavedAddressesList: assign({ | |
prevLocation: () => 'savedAddressesList' | |
}), | |
prevEditAddressExisting: assign({ | |
prevLocation: () => 'editAddressExisting' | |
}), | |
prevEditAddressNew: assign({ | |
prevLocation: () => 'editAddressNew' | |
}), | |
prevAdjustPinExisting: assign({ | |
prevLocation: () => 'adjustPinExisting' | |
}), | |
clearPrevLocation: assign({ | |
prevLocation: undefined | |
}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment