Skip to content

Instantly share code, notes, and snippets.

View coodoo's full-sized avatar

Jeremy Lu coodoo

  • Right here, right now.
View GitHub Profile
{
id: 'Root',
initial: 'after map loaded',
states: {
'before map loaded': {
on: {},
states: {}
},
'after map loaded': {
on: {},
@coodoo
coodoo / statechart-xstate.md
Last active October 24, 2025 17:54
Extensive research of statecharts with a focus on front-end development.

The case for statechart and xstate -- why it matters and how we can benefit from it

Bottom line up front

  • redux is a global data management tool, not a proper state management tool, hence causing a lot of troubles

  • statecharts is an extension to Finite State Machine (FSM) which provides explicit and safe state management capabilities, perfectly fit for front-end development

  • statecharts had been used intensivelly in all industries (be it embedded systems, hardware, electronics, aeronautics, automotive, game development and more), it's us front-end developers late to the party

@coodoo
coodoo / machine.js
Last active August 30, 2019 08:53
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@coodoo
coodoo / useEffect.js
Created August 29, 2019 05:26
[Request for comment] Is there any potential issues handling componentDidMount and componentDidUp with useHooks in this manner?
const once = useRef(false)
useEffect(() => {
if(once.current === false){
once.current = true
// do things as were in componentDidMount
return
}
@coodoo
coodoo / dfa.js
Last active August 11, 2019 06:31
const T = {
INT: 'INT',
SIGN: 'SIGN',
DOT: 'DOT',
EXPO: 'EXPO',
SPACE: 'SPACE',
INVALID: 'INVALID',
EMPTY: 'EMPTY',
}
Bus App
idle
DOOR_OPEN -> loading
loading
DOOR_CLOSE -> stopped
#要放 cond 因為 close 不代表有放入 cd
loadError
#
stopped
ON_EJECT -> idle
Bus App
display
RELOAD -> loading
loading
LOAD_OK -> display
LOAD_FAIL -> error
error
RELOAD -> loading
@coodoo
coodoo / SketchSystems.spec
Last active April 6, 2019 07:38
Gallery App
Gallery App
gallery
SEARCH -> loading
SELECT_PHOTO -> photo
RELOAD -> gallery
loading
CANCEL -> gallery
SEARCH_FAILED -> error
SEARCH_SUCCESS -> gallery
error
@coodoo
coodoo / fat.js
Created August 6, 2018 08:11
How to write fat arrow function.
import io from 'socket.io-client'
const A = require('automerge')
const foo = bar => {
bar.map( b => b.title )
}
startConnection() {
this.socket = io('http://localhost:5000')
@coodoo
coodoo / a.hs
Last active January 8, 2018 01:06
Find first not repeated char in a string. "Technical question" -> h. "Backend" -> b
-- f (x:xs) = case x `elem` xs of
-- True -> f xs
-- False -> x
f s = f' $ map toLower s
where
f' (x:xs) =
case x `elem` xs of
True -> f' xs
False -> x