Skip to content

Instantly share code, notes, and snippets.

@alavkx
alavkx / App.re
Created September 15, 2019 18:57
Find the bug!
type track = {
name: string,
artist: string,
};
let tracks = [|
{artist: "Kromestar", name: "007"},
{artist: "Kromestar", name: "008"},
{artist: "Kromestar", name: "009"},
{artist: "Kromestar", name: "010"},
{artist: "Kromestar", name: "011"},
@alavkx
alavkx / Player.re
Created September 15, 2019 22:51
Audio player state model
type progress =
| Stopped
| Playing
| Rewinding
| FastForwarding
| Paused;
type playerState = {
status: progress,
activeTrackIndex: option(int),
};
@alavkx
alavkx / machine.js
Created August 10, 2020 21:48
Generated by XState Viz: https://xstate.js.org/viz
const fetchQuizData = () =>
fetch(
`https://opentdb.com/api.php?amount=10&difficulty=hard&type=boolean`,
).then(response => response.json())
const normalizeQuizData = (data) =>
data.reduce(
(acc, obj) => [
...acc,
{
@alavkx
alavkx / machine.js
Last active August 13, 2020 19:55
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@alavkx
alavkx / machine.js
Last active September 11, 2020 20:17
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@alavkx
alavkx / machine.js
Created September 16, 2020 19:44
Generated by XState Viz: https://xstate.js.org/viz
const optimisticInputMachine = initial => Machine({
id: 'optimisticInput',
initial: 'idle',
context: {
value: initial,
savedValue: initial,
},
states: {
idle: {
on: {
@alavkx
alavkx / machine.js
Created October 2, 2020 16:17
Generated by XState Viz: https://xstate.js.org/viz
const optimisticInputMachine = initial => Machine({
id: 'optimisticInput',
initial: 'idle',
context: {
value: initial,
savedValue: initial,
},
states: {
idle: {
on: {
@alavkx
alavkx / machine.js
Last active October 8, 2020 13:11
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@alavkx
alavkx / machine.js
Last active March 1, 2021 19:57
Generated by XState Viz: https://xstate.js.org/viz
const assignField = (name) => assign({ [name]: (ctx, event) => event.payload });
const initialContext = {
agreeToTerms: undefined,
};
const quoteAcceptionMachine = Machine({
id: 'quoteAcception',
initial: 'loading',
context: initialContext,
meta: {
@alavkx
alavkx / machine.js
Created October 19, 2020 19:56
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions