This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This script is meant to be used with lint-staged receiving changed files as arguments. | |
It checks if file has "rules-disabled-on" header present with date in the past. | |
If yes, it reports files that need to be reformatted. | |
*/ | |
const _ = require('lodash') | |
const fs = require('fs') | |
const moment = require('moment') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const assessmentMachine = Machine( | |
{ | |
id: "assessment", | |
initial: "phq9_1", | |
context: { | |
phq9: 0, | |
gad7: 0, | |
mhq: false, | |
answers: [] | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import _, { Dictionary, isNil, pickBy, mapValues } from 'lodash' | |
const { database: firebase } = require('firebase-admin') | |
export const FIREBASE_TIMESTAMP = firebase.ServerValue.TIMESTAMP | |
let cache = {} | |
const convertEmptyToNull = (obj: any): any => { | |
if (isNil(obj)) { | |
return null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The idea is that the machine is used by a single cloud function / endpoint, which is called either periodically or based on | |
- Health check using periodic process, such as Google Cloud Scheduler or cron | |
- On failure, schedule additional checks, for ex. using Google Cloud Tasks | |
- If failures continue, restart the system | |
- Go to normal mode of operation if all good | |
*/ | |
// To visualize statechart, copy paste code to https://statecharts.github.io/xstate-viz/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To visualize statechart, copy paste code to https://statecharts.github.io/xstate-viz/ | |
// Available variables: | |
// Machine (machine factory function) | |
// assign (action) | |
// XState (all XState exports) | |
const healthCheck = Machine({ | |
id: 'healthCheck', | |
context: { attempts: 0 }, | |
initial: 'normal', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let i = 0 | |
Machine({ | |
on: { | |
ERROR: 'restarting', | |
}, | |
invoke: { | |
src: 'subscribeToStatus', | |
}, | |
initial: 'running', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const XState = require('xstate') | |
const { Machine, interpret } = XState | |
const { raise } = XState.actions | |
/* | |
run from cli using: | |
node xstate-onentry-timing-bug.js [sync|async|raise] | |
*/ |
NewerOlder