Skip to content

Instantly share code, notes, and snippets.

@shmidt-i
Last active August 14, 2019 14:02
Show Gist options
  • Save shmidt-i/cc42bdc3721ee06e99af7f3efce7442f to your computer and use it in GitHub Desktop.
Save shmidt-i/cc42bdc3721ee06e99af7f3efce7442f to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// Machine (machine factory function)
// assign (action)
// XState (all XState exports)
const fetchMachine = Machine({
id: "theWholeSelect",
initial: "init",
context: {
currentValueToShow: null,
selectedValue: null,
isDesktop: true,
placeholder: "some placeholder"
},
states: {
init: {
on: {
INIT: {
actions: "initializeContext",
target: "closed"
}
}
},
closed: {
on: {
OPEN: [
{target: 'opened.custom', cond: 'isDesktop'},
{target: 'opened.native' }
]
}
},
opened: {
states: {
custom: {},
native: {},
},
on: {
CLOSE: 'closed',
SELECT: {
actions: ['setSelectedValue', 'setCurrentValueToShow'],
target: 'closed'
}
}
}
},
guards: {
isDesktop: ctx => !!ctx.isDesktop
},
actions: {
initializeContext: (ctx, event) =>
assign(event.context),
setSelectedValue: (ctx, event) =>
assign({selectedValue: event.value}),
setCurrentValueToShow: (ctx, event) =>
assign({currentValueToShow: event.value})
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment