Last active
April 15, 2020 18:39
-
-
Save tmlangley/a06e4b9eceb941be51a9c88bb56774ce 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
const FiltersMachine = Machine({ | |
id: 'filters', | |
initial: 'loading', | |
context: { | |
results: [], | |
filterParams: [] | |
}, | |
states: { | |
loading: { | |
initial: 'fetchingAllFilterOptions', | |
states: { | |
fetchingAllFilterOptions: { | |
after: { | |
1500: '#idle' | |
}, | |
exit: sendParent('FILTERS_READY') | |
}, | |
refiningFilters: { | |
after: { | |
1500: '#idle' | |
}, | |
exit: sendParent('REFINEMENT_SUCCESS') | |
} | |
}, | |
}, | |
idle: { | |
id: 'idle', | |
on: { | |
REFINE_FILTERS: 'loading.refiningFilters', | |
} | |
}, | |
failure: { | |
on: { | |
RETRY: 'loading' | |
} | |
} | |
}}); | |
const ResultsMachine = Machine({ | |
id: 'resultsMachine', | |
initial: 'defaultContent', | |
states: { | |
defaultContent: { | |
on: { | |
REFINING_FILTERS: 'loading' | |
} | |
}, | |
loading: { | |
after: { | |
1500: 'success' | |
} | |
}, | |
noResults: {}, | |
error: {}, | |
success: {} | |
}, | |
}); | |
const PassListPageRequests = Machine({ | |
id: 'passListPageRequests', | |
initial: 'loading', | |
states: { | |
loading: { | |
initial: 'initialFilters', | |
invoke: [{ | |
id: 'resultsMachine', | |
src: ResultsMachine | |
}, { | |
id: 'filtersMachine', | |
src: FiltersMachine | |
}], | |
states: { | |
initialFilters: { | |
on: { | |
FILTERS_READY: '#waitingForRefinement' | |
}, | |
}, | |
refiningFilters: { | |
entry: [ | |
send('REFINE_FILTERS', {to: 'filtersMachine'}), | |
send('REFINING_FILTERS', {to: 'resultsMachine'}) | |
], | |
on: { | |
REFINEMENT_SUCCESS: { | |
target: '#waitingForRefinement' | |
} | |
} | |
} | |
}, | |
}, | |
waitingForRefinement: { | |
id: 'waitingForRefinement', | |
on: { | |
FILTERS_CHANGED: 'loading.refiningFilters' | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment