Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function isMobile(ctx) {
- return ctx.screen === 'mobile'
- }
- const updateOrientation = assign({
- screen: ctx => ctx.screen === 'desktop' ? 'mobile' : 'desktop'
- });
- const machine = Machine({
- initial: 'X',
- context: {
- screen: 'desktop'
- },
- states: {
- X: {
- on: {
- NEXT: [
- { target: 'AB', cond: isMobile },
- { target: 'A' }
- ],
- REORIENT: { actions: updateOrientation }
- }
- },
- A: {
- on: {
- BACK: 'X',
- NEXT: 'B',
- REORIENT: { actions: updateOrientation }
- }
- },
- B: {
- on: {
- BACK: 'A',
- NEXT: 'Y',
- REORIENT: {
- target: 'AB',
- actions: updateOrientation
- }
- }
- },
- AB: {
- on: {
- BACK: 'X',
- NEXT: 'Y',
- REORIENT: { actions: updateOrientation }
- }
- },
- Y: {
- type: 'final',
- }
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement