When using x state app machine. How do I set the initial state to a variable? I want the intial state to be either full screen or menu, when the boolean value is sent from another file. I want to send a boolean value from some page to the app machine, and change the initial state based on that value.
VIDEO MACHINE
{
id: "interactiveVideoMachine",
context: {
useFullscreenDefault: false,
},
user: {
id: "user",
initial: `${useFullscreen ? "fullscreen" : "menu"}`, // <--here
states: {
menu: {/*...*/},
fullscreen: {/*...*/},
},
on: {
SET_FULLSCREEN_DEFAULT: {
actions: "setFullscreenDefault",
},
},
},
};
{
actions: {
setFullscreenDefault,
},
};
ASSIGN ACTION
const setFullscreenDefault: AssignAction<
InteractiveVideoContext,
InteractiveVideoEvent
> = actions.assign({
useFullscreenDefault: (ctx, event) => event.useFullscreenDefault,
});
SVELTE FILE
let isFullscreenDefault: boolean;
const handleFullScreenDefault = () => {
console.log(isFullscreenDefault); //log here
if (interactiveVideoStateService) {
interactiveVideoStateService.send({
type: "SET_FULLSCREEN_DEFAULT",
isFullscreenDefault,
});
}
};