Skip to content

Instantly share code, notes, and snippets.

@kyleshevlin
Created December 4, 2019 23:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyleshevlin/50d5da849033e4fd6d7773a06bf89055 to your computer and use it in GitHub Desktop.
Save kyleshevlin/50d5da849033e4fd6d7773a06bf89055 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const assetManagerViewMachine = Machine(
{
id: "assetManagerView",
initial: "closed",
context: {
assetsSelected: 0
},
states: {
closed: {
on: {
OPEN_SIDE: "side",
OPEN_MASTER: "master"
}
},
side: {
on: {
CLOSE: "closed",
OPEN_MASTER: "master"
}
},
master: {
exit: ['resetAssetsSelected'],
on: {
CLOSE: "closed",
OPEN_SIDE: "side",
SELECT_ASSET: {
target: ".selecting",
actions: ["incAssetsSelected"]
}
},
initial: "idle",
states: {
idle: {},
selecting: {
on: {
DESELECT_ASSET:{
target: 'deselecting',
actions: ['decAssetsSelected']
}
}
},
deselecting: {
on: {
"": [
{ target: "idle", cond: "noAssetsSelected" },
{ target: "selecting" }
]
}
}
}
}
}
},
{
actions: {
incAssetsSelected: assign({
assetsSelected: ctx => ctx.assetsSelected + 1
}),
decAssetsSelected: assign({
assetsSelected: ctx => ctx.assetsSelected - 1
}),
resetAssetsSelected: assign({
assetsSelected: 0
})
},
guards: {
noAssetsSelected: ctx => ctx.assetsSelected === 0
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment