Skip to content

Instantly share code, notes, and snippets.

@simonedavico
simonedavico / keychainAccessStates.js
Last active January 20, 2021 22:39
Nested states for the payment authorisation state machine described in my blog post: https://medium.com/@sdavico/integrate-xstate-with-react-native-and-react-navigation-21ead87391da
import { Machine, send, assign, actions } from "xstate";
const { choose, log } = actions;
const keychainAccessStates = {
initial: "checkingBiometricFactor",
states: {
checkingBiometricFactor: {
on: {
RETRY: { target: "checkingBiometricFactor", internal: false },
@simonedavico
simonedavico / machine.js
Last active December 31, 2020 08:04
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@simonedavico
simonedavico / paymentAuthorizationMachine.js
Last active January 11, 2021 17:26
Payment Authorization Flow with XState
import { Machine, assign } from 'xstate';
const paymentAuthorizationMachine = Machine({
id: 'paymentAuthorization',
initial: 'checkPrerequisites',
// we will track payment authorization details in the machine's context
context: {
paymentAuthorizationId: null,
expiresOn: null,
// ...more fields
@simonedavico
simonedavico / decorateAsyncRoute.md
Created January 17, 2017 15:48
Decorating async route definitions from react-redux-starter-kit (React+React-Router+Redux and Webpack code splitting)

Context

Today I was working on a project in which I use React, React-Router and Redux for the front-end. I also use webpack to build the project, and, since I need dynamic routing, I employ require and require.ensure to exploit Webpack's [https://webpack.github.io/docs/code-splitting.html](code splitting feature). I borrowed this idea from react-redux-starter-kit, and for some use cases it is awesome. A dynamic route looks like this: