Last active
August 14, 2019 14:02
-
-
Save shmidt-i/cc42bdc3721ee06e99af7f3efce7442f 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 (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