Created
September 22, 2019 13:39
-
-
Save keksipurkki/72cb1212f5b4002bacfee3f189622d38 to your computer and use it in GitHub Desktop.
This file contains 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
export function uuidv4() { | |
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) { | |
const r = (Math.random() * 16) | 0, | |
v = c == "x" ? r : (r & 0x3) | 0x8; | |
return v.toString(16); | |
}); | |
} | |
export function lazy<T>(value: T) { | |
return () => value; | |
} | |
export function effects<V>(...fns: Consumer<V>[]) { | |
return (v: V) => fns.forEach(f => f(v)); | |
} | |
export function debounce<F extends AnyFunction>(fn: F, timeout: number): F { | |
let timer = 0; | |
const debounced = (...args: any[]) => { | |
window.clearTimeout(timer); | |
timer = window.setTimeout(fn, timeout, ...args); | |
}; | |
return debounced as F; | |
} | |
export function assert<E>(expr: E, message = "assertion failed") { | |
if (!expr) throw new Error(message); | |
} | |
export function isTodo(todo: Maybe<TodoNote>): todo is TodoNote { | |
return todo.type !== "Nil"; | |
} | |
export { compose } from "redux"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment