1.0.8 • Published 5 years ago

@rbxts/dumpster v1.0.8

Weekly downloads
8
License
ISC
Repository
-
Last release
5 years ago

Dumpster

Written by Fraktality ( Source )

Crash Course

import Dumpster from "@rbxts/dumpster";
import { RunService } from "@rbxts/services";

// creation
const dumpster = new Dumpster();
const myPart = new Instance("Part");

// Instance
dumpster.dump(myPart);

// RBXScriptConnection
dumpster.dump(RunService.Stepped.Connect(() => print("Step!")));

// Function
dumpster.dump(() => print("Cleaned!"));

// User created class with `.destroy()`
class Foo { destroy() {} }
dumpster.dump(new Foo());

// later..
dumpster.burn();

// You can optionally pass a custom handler function to override the default callback
// (which is normally chosen using the `typeof` function).
// This is especially handy for custom classes:

class Obj {
	remove() {}
}

dumpster.dump(new Obj(), obj => obj.remove());

// You can also pattern your classes as having a static destructor member
class Item {
	static destructor(item: Item) {
		item.remove();
	}
	remove() {}
}

// Then re-use the same callback for every cleanup
dumpster.dump(new Item(), Item.destructor);
dumpster.dump(new Item(), Item.destructor);