disposable
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
using
feature explanation in TypeScript 5.2 docs
import { disposable } from "https://esm.town/v/postpostscript/disposable";
using state = disposable(
{
x: 1,
y: 2,
},
(value) => console.log("state disposed", value),
);
// state disposed { x: 1, y: 2, [Symbol(Symbol.dispose)]: [Function (anonymous)] }
or, to use a proxy instead of modifying the original object:
using state = disposable(
{
x: 1,
y: 2,
},
(value) => console.log("proxyState disposed", value),
true,
);
// proxyState disposed { x: 1, y: 2 }
Migrated from folder: Utils/disposable