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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions |
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
function memo(fn) { | |
const dict = {} | |
let id | |
const perform = { calls: 0, memoHits: 0 } | |
return (...args) => { | |
perform.calls++ | |
clearTimeout(id) | |
id = setTimeout(() => { | |
console.log(`memo hit rate = ${perform.memoHits}/${perform.calls}`) | |
}, 1000) |
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
import { createMachine, useStateMachine } from "./stateMachine"; | |
const machine = createMachine({ | |
initial: "saved", | |
context: { | |
input: "" | |
}, | |
states: { | |
saved: { | |
edit: "hasChanges" |
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
function useMouseSpeed(updateInterval = 500) { | |
const lastUpdateRef = useRef(Date.now()) | |
const prevPositionRef = useRef<MousePosition | null> (null) | |
const currentPositionRef = useRef<MousePosition | null> (null) | |
const [speed, setSpeed] = useState(0) | |
useEffect(() => { | |
function trackMouse({ pageX: x, pageY: y }: MouseEvent) { | |
x = x / window.innerWidth | |
y = y / window.innerHeight |
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
function openPopup(url: string, height: number, width: number) { | |
if (typeof window !== "undefined") { | |
const newwindow = window.open( | |
url, | |
"Share Window", | |
`height=${height}, width=${width}, top=` + | |
(window.innerHeight / 2 - height) + | |
", left=" + | |
(window.innerWidth / 2 - width) + | |
", toolbar=0, location=0, menubar=0, directories=0, scrollbars=0" |
OlderNewer