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
function match(handlers, defaultFn) { | |
return key => { | |
return (...args) => { | |
if (typeof handlers[key] === 'function') { | |
return handlers[key].call(this, ...args); | |
} | |
return defaultFn(...args); | |
} | |
} |
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 doOnError = (fn, onError) => { | |
return (...args) => { | |
try { | |
return fn.apply(this, args); | |
} catch (err) { | |
onError(err); | |
throw err; | |
} | |
} | |
}; |
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 measure = (fn) => { | |
return (...args) => { | |
console.log(fn.name); | |
let t0 = performance.now(); | |
let res = fn.apply(this, args); | |
let t1 = performance.now(); | |
console.log(t1 - t0); | |
return res; | |
} | |
}; |
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
type alias Field = | |
{ id : String | |
, label : String | |
, value : String | |
, fieldset : List Field | |
} | |
-- This type alias is part of a mutually recursive set of type aliases. |
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
// http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery | |
const hashCode = (s) => { | |
return s.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0); | |
}; | |
const memoizeObservable = (fn) => { | |
let cache = {}; | |
return (...args) => { | |
let entryKey = hashCode(JSON.stringify(args)); |
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 dispatcher = createDispatcher( | |
store, | |
getState => [thunkMiddleware(getState)] | |
); | |
const redux = createRedux(dispatcher); | |
class App extends React.Component { | |
handleChange(field) { | |
const {id, value} = field; |
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 dispatcher = createDispatcher( | |
store, | |
getState => [thunkMiddleware(getState)] | |
); | |
const redux = createRedux(dispatcher); | |
class App extends React.Component { | |
handleChange(field) { | |
const {id, value} = field; |