Created
December 4, 2019 23:56
-
-
Save kyleshevlin/50d5da849033e4fd6d7773a06bf89055 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
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