UNPKG

haunted

Version:
25 lines (24 loc) 540 B
import { current, notify } from "./interface"; import { hookSymbol } from "./symbols"; class Hook { id; state; constructor(id, state) { this.id = id; this.state = state; } } function use(Hook, ...args) { let id = notify(); let hooks = current[hookSymbol]; let hook = hooks.get(id); if (!hook) { hook = new Hook(id, current, ...args); hooks.set(id, hook); } return hook.update(...args); } function hook(Hook) { return use.bind(null, Hook); } export { hook, Hook };