@rbxts/dumpster

Written by Fraktality ( Source )

Usage no npm install needed!

<script type="module">
  import rbxtsDumpster from 'https://cdn.skypack.dev/@rbxts/dumpster';
</script>

README

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);