Skip to content

Instantly share code, notes, and snippets.

View davidkpiano's full-sized avatar
🎹
Working on XState Dev Tools

David Khourshid davidkpiano

🎹
Working on XState Dev Tools
View GitHub Profile
title published description tags
Redux is half of a pattern.
false

Redux is fantastic.

Some of you might disagree, so here's the main reason why it's fantastic: over the last few years, it has popularized the idea of using message-passing to manage application state. Instead of making arbitrary method calls to various class instances or mutating data structures, we now can think of state as being in a "predictable container" that only changes as a reaction to these "messages."

@davidkpiano
davidkpiano / machine.js
Created January 6, 2020 03:22
Generated by XState Viz: https://xstate.js.org/viz
const increment = assign({
count: ctx => ctx.count + 1
});
const decrement = assign({
count: ctx => ctx.count - 1
});
const MIN = 0;
const MAX = 10;
@davidkpiano
davidkpiano / machine.js
Last active December 16, 2019 16:31
Generated by XState Viz: https://xstate.js.org/viz
function dependenciesResolved(ctx) {
return ctx.depCount === 5;
}
const workflow = Machine({
id: 'dash workflow',
initial: 'resolving dependencies',
context: {
depCount: 0
},
@davidkpiano
davidkpiano / machine.js
Created December 14, 2019 19:24
Generated by XState Viz: https://xstate.js.org/viz
const everyoneApproved = ctx => ctx.approvals >= 2;
const machine = Machine({
id: 'approval',
initial: 'requesting',
context: {
approvals: 0
},
states: {
requesting: {
@davidkpiano
davidkpiano / machine.js
Last active November 29, 2019 13:19
Generated by XState Viz: https://xstate.js.org/viz
function fetchData() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(Math.floor(Math.random() * 100));
}, 2000)
})
}
const fetchMachine = Machine({
id: 'fetch',
@davidkpiano
davidkpiano / machine.js
Created November 24, 2019 13:24
Generated by XState Viz: https://xstate.js.org/viz
const vendingMachine = Machine({
id: 'vending',
initial: 0,
states: {
0: {
on: {
5: '5',
10: '10',
20: '20'
}
@davidkpiano
davidkpiano / machine.js
Created November 18, 2019 23:23
Generated by XState Viz: https://xstate.js.org/viz
const states = {
IDLE: "IDLE",
HOVERING: "HOVERING",
UPLOADING: "UPLOADING",
SUCCESS: "SUCCESS"
};
const events = {
MOUSEENTER: "MOUSEENTER",
MOUSELEAVE: "MOUSELEAVE",
@davidkpiano
davidkpiano / machine.js
Created November 13, 2019 13:27
Generated by XState Viz: https://xstate.js.org/viz
const dogFetcherMachine = Machine({
id: "dog fetcher",
initial: "idle",
context: {
dog: null,
error: null
},
states: {
idle: {
on: { FETCH: "loading" }
@davidkpiano
davidkpiano / machine.js
Created November 7, 2019 01:42
Generated by XState Viz: https://xstate.js.org/viz
const getBlobMetadata = () => new Promise(res => {
setTimeout(() => {
console.log('yeah')
res({
Path: 'somepath.csv'
});
}, 2000)
});
const readFile = () => new Promise((res, rej) => {
@davidkpiano
davidkpiano / machine.js
Created November 6, 2019 19:47
Generated by XState Viz: https://xstate.js.org/viz
const stepMachine = Machine(
{
id: "steps",
initial: "step1",
states: {
step1: {
on: {
NEXT: "step2"
}
},