Skip to content

Instantly share code, notes, and snippets.

@erickeno
erickeno / FormExample.re
Created February 25, 2020 16:03 — forked from busypeoples/FormExample.re
Form Example in ReasonML
type validation('a) =
| NotEmpty
| Custom('a);
type t = string;
let validate = (rule, value, values) =>
switch (rule) {
| NotEmpty => String.length(value) > 0
| Custom(fn) => fn(value, values)
@erickeno
erickeno / machine.js
Last active January 24, 2020 23:41
Gym checkin machine
const getClasses = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve({ name: 'erick', isTrue: true})
}, 5000)
})
}
const getReservations = () => {
return new Promise((resolve, reject) => {
@erickeno
erickeno / machine.js
Created January 2, 2020 23:51
Generated by XState Viz: https://xstate.js.org/viz
const reservationCheckin = () => {
return Promise.resolve()
}
const checkinMachine = Machine(
{
id: 'checkin',
initial: 'idle',
context: { data: { cancelled: false, checkin: '0',spots_available: 10 } },
states: {
idle: {
@erickeno
erickeno / machine.js
Last active December 31, 2019 23:04
Generated by XState Viz: https://xstate.js.org/viz
const reservationModal = {
initial: 'closed',
states: {
closed: {
on: {
OPEN: 'open'
}
},
open: {
on: {
@erickeno
erickeno / A.markdown
Created December 26, 2019 23:07 — forked from larrybotha/A.markdown
XState + AWS Amplify example

XState + AWS Amplify example

A breakdown of a project that uses XState to manage state for authenticating a user with Cognito, and then finding the authorized application user with an invoked machine.

  1. create auth machine
  2. create auth context
  3. handle AWS authentication
  4. once user authenticates with Cognito, redirect to user route to get user from db
  5. at user route use userMachine service from authMachine to get application user
  6. once associated application user is found, send user to organization route to allow user to associate session with specific organization
@erickeno
erickeno / index.js
Last active January 24, 2020 23:42
microwave machine
const openMic = {
initial: 'idle',
states: {
idle: {
on: {
ADD_THIRTY_SEC: { actions: 'addThirtySec', target: 'running' },
ADD_TIME: { actions: 'addTime' },
SET_TIME: { actions: 'setTime' },
START: { target: 'running', cond: ({ countdown }) => countdown !== 0 },
},
@erickeno
erickeno / machine.js
Created December 22, 2019 22:30
Generated by XState Viz: https://xstate.js.org/viz
const emailStates = {
initial: "noError",
states: {
noError: {},
error: {
initial: "empty",
states: {
empty: {},
badFormat: {},
noAccount: {},
@erickeno
erickeno / machine.js
Last active December 19, 2019 23:27
Generated by XState Viz: https://xstate.js.org/viz
const initialAppContextItems = [
{
id: 0,
title: 'Summer Photos',
owner: 'Anthony Stevens',
updatedAt: new Date(Date.UTC(2017, 6, 12)),
},
{
id: 1,
title: 'Surfing',
@erickeno
erickeno / machine.js
Last active January 24, 2020 23:39
classMachine
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@erickeno
erickeno / machine.js
Last active September 8, 2019 16:44
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// Machine (machine factory function)
// assign (action)
// XState (all XState exports)
const fetchMachine = Machine({
id: 'fetch',
context: { attempts: 0 },
initial: 'idle',