Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeremy Lu coodoo

View GitHub Profile
View machine.js
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@coodoo
coodoo / useEffect.js
Created Aug 29, 2019
[Request for comment] Is there any potential issues handling componentDidMount and componentDidUp with useHooks in this manner?
View useEffect.js
const once = useRef(false)
useEffect(() => {
if(once.current === false){
once.current = true
// do things as were in componentDidMount
return
}
View dfa.js
const T = {
INT: 'INT',
SIGN: 'SIGN',
DOT: 'DOT',
EXPO: 'EXPO',
SPACE: 'SPACE',
INVALID: 'INVALID',
EMPTY: 'EMPTY',
}
View SketchSystems.spec
Bus App
idle
DOOR_OPEN -> loading
loading
DOOR_CLOSE -> stopped
#要放 cond 因為 close 不代表有放入 cd
loadError
#
stopped
ON_EJECT -> idle
View SketchSystems.spec
Bus App
display
RELOAD -> loading
loading
LOAD_OK -> display
LOAD_FAIL -> error
error
RELOAD -> loading
View SketchSystems.spec
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 Aug 6, 2018
How to write fat arrow function.
View fat.js
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 / index.js
Created Oct 24, 2014
Pre-render with react v.0.12
View index.js
var React = require('react');
require('node-jsx').install();
var MyApp = React.createFactory( require('./myApp') );
var app = new MyApp({items:['a', 'b', 'c']});
var str = React.renderToString( app );
console.log( 'str: ', str, '\n\n\n', app );
@coodoo
coodoo / a.hs
Last active Jan 8, 2018
Find first not repeated char in a string. "Technical question" -> h. "Backend" -> b
View a.hs
-- 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
View gist:59891964b06a603e2dc8
- 我想要挑戰isomorphic,但目前好像比較少redux配isomorphic又配上webpack的方案
- 這個範例可看,最近全部改寫過
- https://github.com/coodoo/react-redux-isomorphic-example
- 注意下面幾點
- js/bootClient.js 與 js/bootServer.js
- bootServer.js 負責做 server-render