Skip to content

Instantly share code, notes, and snippets.

@willgriffiths
Last active July 22, 2019 06:54
Show Gist options
  • Save willgriffiths/9b3cebfe5a764961304770a006edd487 to your computer and use it in GitHub Desktop.
Save willgriffiths/9b3cebfe5a764961304770a006edd487 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const playerMachine = Machine({
id: "player",
initial: "paused",
states: {
paused: {
on: {
PLAY: 'playing',
STOP: 'stopped'
}
},
playing: {
on: {
PAUSE: 'paused',
STOP: 'stopped'
}
},
stopped: {
on: {
PAUSE: 'paused',
PLAY: 'playing'
}
}
}
}
)
const selectionMachine = Machine(
{
id: "selection",
initial: "selected",
context: {
selectedTag: 55
},
states: {
none: {
on: {
SELECT_TAG: {
target: "selected",
actions: assign({
selectedTag: (ctx, e) => e.id
})
}
}
},
selected: {
on: {
SELECT_TAG: {
target: "",
actions: assign({
selectedTag: (ctx, e) => e.id
})
},
CLEAR_SELECTION: {
target: "none",
actions: assign({
selectedTag: (ctx, e) => null
})
}
}
}
}
},
{
actions: {
selectTag: assign({
selectedTag: (ctx, e) => e.id
})
}
}
);
// const fetchMachine = Machine({
// id: 'fetch',
// initial: 'idle',
// context: {
// retries: 0
// },
// states: {
// idle: {
// on: {
// FETCH: 'loading'
// }
// },
// loading: {
// on: {
// RESOLVE: 'success',
// REJECT: 'failure'
// }
// },
// success: {
// type: 'final'
// },
// failure: {
// on: {
// RETRY: {
// target: 'loading',
// actions: assign({
// retries: (context, event) => context.retries + 1
// })
// }
// }
// }
// }
// });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment