UNPKG

@shined/reactive

Version:

⚛️ Proxy-driven state library for JavaScript application, Intuitive, Flexible and Written in TypeScript.

11 lines (9 loc) 323 B
import { proxy } from './proxy.js' import { snapshot } from './snapshot.js' export function produce<State extends object>(obj: State, draftHandler: (draft: State) => void) { let state: State | null = proxy(obj) draftHandler(state) const nextSnapshot = snapshot(state) state = null return nextSnapshot as State }