@benev/slate
Version:
frontend web stuff
23 lines (17 loc) • 365 B
text/typescript
/** @deprecated use `Trashbin` instead */
export class Trashcan {
#can: (() => void)[] = []
bag = <T>(item: T) => ({
dump: (destroy: (item: T) => void) => {
this.#can.push(() => destroy(item))
return item
}
})
mark = (fn: () => void) => {
this.#can.push(fn)
}
dispose = () => {
this.#can.forEach(destroy => destroy())
this.#can = []
}
}