mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
* use docker for build steps that require linux when not on linux * use fuse for overlay * quiet mountpoint * node 22 * misc fixes * make shasum more compliant * optimize download-base-image.sh with cleaner url handling and checksum verification * fix script * fixes #2900 * bump node and npm versions in web readme * Minor pl.ts fixes * fixes in response to synapse issues * beta.8 * update ts-matches * beta.11 * pl.ts finetuning --------- Co-authored-by: Mariusz Kogen <k0gen@pm.me> Co-authored-by: Matt Hill <mattnine@protonmail.com>
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
export abstract class Drop {
|
|
private static weak: { [id: number]: Drop } = {}
|
|
private static registry = new FinalizationRegistry((id: number) => {
|
|
const weak = Drop.weak[id]
|
|
if (weak) weak.drop()
|
|
})
|
|
private static idCtr: number = 0
|
|
private id: number
|
|
private ref: { id: number } | WeakRef<{ id: number }>
|
|
protected constructor() {
|
|
this.id = Drop.idCtr++
|
|
this.ref = { id: this.id }
|
|
const weak = this.weak()
|
|
Drop.weak[this.id] = weak
|
|
Drop.registry.register(this.ref, this.id, this.ref)
|
|
|
|
return new Proxy(this, {
|
|
set(target: any, prop, value) {
|
|
if (prop === "ref") return false
|
|
target[prop] = value
|
|
;(weak as any)[prop] = value
|
|
return true
|
|
},
|
|
})
|
|
}
|
|
protected register() {}
|
|
protected weak(): this {
|
|
const weak = Object.assign(Object.create(Object.getPrototypeOf(this)), this)
|
|
weak.ref = new WeakRef(this.ref)
|
|
return weak
|
|
}
|
|
abstract onDrop(): void
|
|
drop(): void {
|
|
this.onDrop()
|
|
Drop.registry.unregister(this.ref)
|
|
delete Drop.weak[this.id]
|
|
}
|
|
}
|