Last active
August 24, 2021 09:02
-
-
Save pke/7f219282076a0390408733892bfdeef1 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: 'doctorsearch', | |
initial: 'speciality', | |
context: { | |
speciality: "", | |
location: undefined, | |
showFilter: false, | |
filters: [], | |
showDetails: false, | |
}, | |
states: { | |
speciality: { | |
on: { | |
SET_SPECIALITY: { | |
target: 'location', | |
cond: "validateSpeciality", | |
actions: "setSpeciality" | |
} | |
} | |
}, | |
location: { | |
on: { | |
SET_LOCATION: { | |
target: 'search', | |
cond: (context, event) => !!event.value, | |
actions: "setLocation" | |
} | |
} | |
}, | |
search: { | |
on: { | |
TOGGLE_DETAIL: { | |
actions: assign({ | |
showDetails: (context, event) => !context.showDetails | |
}) | |
} | |
} | |
}, | |
} | |
}, { | |
guards: { | |
validateSpeciality: (context, event) => !!event.value | |
}, | |
actions: { | |
setSpeciality: assign({ | |
location: (context, event) => event.value | |
}), | |
setLocation: assign({ | |
location: (context, event) => event.value | |
}) | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment