Skip to content

Instantly share code, notes, and snippets.

View hrafnkellpalsson's full-sized avatar

Hrafnkell Pálsson hrafnkellpalsson

View GitHub Profile
// API of the search prop is based on React's setState API
// crp stands for "create redirect params"
type O = Record<string, any>
type CrpBase = {
pathname: string
status: number
}
type CrpObj = CrpBase & { search: O }
type CrpFunc = CrpBase & {
// API of the search prop is based on React's setState API
// crp stands for "create redirect params"
type O = Record<string, any>
type CrpBase = {
pathname: string
status: number
}
type CrpObj = CrpBase & { search: O }
type CrpFunc = CrpBase & {
@hrafnkellpalsson
hrafnkellpalsson / authMachine.js
Last active April 6, 2021 03:58
Auth state machine for AWS Amplify Authenticator component
import { Machine } from "xstate"
import Auth from "@aws-amplify/auth"
import { Hub } from "@aws-amplify/core"
import { sentry } from "../sentry"
import { queryCache } from "react-query"
// Some of the events from the Hub auth channel are in the documentation here
// https://docs.amplify.aws/lib/auth/auth-events/q/platform/js
// Even more events in the source code
// https://github.com/aws-amplify/amplify-js/blob/92d8d800256119d1ba84bb90097f91a983b1e5c0/packages/auth/src/Auth.ts
@hrafnkellpalsson
hrafnkellpalsson / machine.js
Created September 26, 2020 19:44
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
const gathering = Machine({
id: "gathering",
initial: "started",
states: {
started: {
entry: (ctx, e) => console.log('"Started" entry action executed'),
exit: (ctx, e) => console.log('"Started" exit action executed'),
on: {
SAME_SAME: {
target: "started",
const birthday = Machine({
id: "birthday",
initial: "notStarted",
states: {
started: {
initial: "boring",
entry: (ctx, e) => console.log('Parent entry action executed'),
exit: (ctx, e) => console.log('Parent exit action executed'),
on: {
CAKE_BONANZA: {
@hrafnkellpalsson
hrafnkellpalsson / machine.js
Last active February 24, 2020 01:35
Generated by XState Viz: https://xstate.js.org/viz
// There must be exactly one initial state, which implies
// there must be at least one finite state.
// const dullHuman = Machine({
// id: 'dullHuman',
// initial: 'idle',
// states: {
// idle: {}
// }
// })
@hrafnkellpalsson
hrafnkellpalsson / machine.js
Last active February 19, 2020 23:38
Generated by XState Viz: https://xstate.js.org/viz
// * Stubbed out methods so we can copy the machine to the xstate visualizer
const fetchAll = () => {}
const setRemoteData = () => {}
const isDeselectingLastSelectedItem = () => {}
const selectMenuItem = () => {}
const deselectMenuItem = () => {}
const isNotCreated = (ctx, e) => false
const isNotYetActive = (ctx, e) => false
const hasOrderedAndIsActive = (ctx, e) => false
const hasOrderedAndIsExpired = (ctx, e) => false
@hrafnkellpalsson
hrafnkellpalsson / machine.js
Last active November 30, 2019 00:58
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
const dogFetcherMachine = Machine({
id: "dog fetcher",
initial: "idle",
context: {
dog: null,
error: null
},
states: {
idle: {
on: { FETCH: "loading" }