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
@davidkpiano
davidkpiano / machine.js
Created March 11, 2020 16:37
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: "delay + state",
type: "parallel",
states: {
status: {
initial: "intros",
states: {
intros: {
after: {
@davidkpiano
davidkpiano / machine.js
Last active July 20, 2022 20:23
Generated by XState Viz: https://xstate.js.org/viz
Machine({
initial: 'idle',
context: {
// the position of the box
x: 0,
y: 0,
// where you clicked
pointerx: 0,
pointery: 0,
// how far from where you clicked
@davidkpiano
davidkpiano / machine.js
Last active March 6, 2020 23:27
Generated by XState Viz: https://xstate.js.org/viz
Machine({
initial: 'idle',
context: {
dx: 0,
dy: 0,
pointerx: 0,
pointery: 0
},
states: {
'idle': {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test</title>
</head>
<body>
@davidkpiano
davidkpiano / machine.js
Last active October 3, 2022 16:21
Generated by XState Viz: https://xstate.js.org/viz
const updatePosition = assign({
position: (_, event) => event.position,
})
function geoService(context, event) {
return cb => {
if (!navigator.geolocation) {
cb({
type: 'error',
error: new Error('Geolocation is not supported'),
@davidkpiano
davidkpiano / reducer-with-effects.js
Last active August 20, 2021 18:58
An idea for actor-model-based effects with reducers
import {
useReducerWithEffects,
// hand-wavey, but meant to be used by React to create something
// external will produce async values sent to components
createEffect
} from 'react';
function fetchUserEffect(id, parentRef) {
const controller = new AbortController();
const signal = controller.signal;
@davidkpiano
davidkpiano / machine.js
Created January 27, 2020 14:53
Generated by XState Viz: https://xstate.js.org/viz
Machine({
"initial": "ingest",
"states": {
"ingest": {
"initial": "idle",
"states": {
"idle": {
"on": {
"DMP.NEWDATACLAIM": "pending"
}
@davidkpiano
davidkpiano / machine.js
Created January 23, 2020 13:57
Generated by XState Viz: https://xstate.js.org/viz
Machine({
"initial": "ingest",
"states": {
"ingest": {
"initial": "pending",
"states": {
"pending": {
"on": {
"RESOLVE": "success",
"ERROR": "failure"
@davidkpiano
davidkpiano / machine.js
Last active January 21, 2020 04:16
Generated by XState Viz: https://xstate.js.org/viz
Machine({
initial: 'inJira',
states: {
inJira: {
on: {
'': [
{
target: 'matchingOrg',
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."