Created
November 17, 2019 17:09
-
-
Save lettertwo/3a2d707faf3c64d43729e6f22d4184ac 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const stickyPortalMachine = Machine({ | |
id: 'stickyPortal', | |
initial: 'invalid', | |
context: { | |
height: 0, | |
stickyStates: [], | |
}, | |
on: { | |
ADD_STICKY_STATE: { | |
target: 'invalid', | |
actions: assign({ | |
stickyStates: (context, event) => { | |
const stickyState = spawn(stickyMachine); | |
return context.stickyStates.concat(stickyState); | |
} | |
}) | |
}, | |
UPDATE_STICKY_STATE: { | |
target: 'invalid', | |
actions: assign({ | |
stickyStates: (context, event) => { | |
const stickyStates = context.stickyStates.slice(); | |
for (const i in stickyStates) { | |
if (stickyStates[i].id === event.stickyState.id) { | |
stickyStates[i] = event.stickyState; | |
} | |
break; | |
} | |
return stickyStates; | |
} | |
}) | |
}, | |
}, | |
states: { | |
valid: { | |
on: { | |
INVALIDATE: 'invalid' | |
} | |
}, | |
invalid: { | |
on: { | |
VALIDATE: { | |
target: 'valid', | |
actions: assign({ | |
height: (context, event) => | |
context.height += event.height | |
}) | |
} | |
} | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment