@rbxts/better-maid
v1.1.0
Published
Essentially @rbxts/janitor but improved (and renamed to Maid due to perference as its shorter). Look at the index.d.ts file for documentation.
Readme
BetterMaid
Essentially @rbxts/janitor but improved (and renamed to Maid due to perference as its shorter). Look at the index.d.ts file for documentation.
Features In Addition To Janitor
Ability to extend Maids
import { Maid } from "shared/maid";
const parentMaid = new Maid();
const childMaid = parentMaid.Extend();
// Add objects to both
parentMaid.Add(() => print("Parent cleanup"), true);
childMaid.Add(() => print("Child cleanup"), true);
// When parent is cleaned up, child is also cleaned up
parentMaid.Cleanup(); // Prints both "Parent cleanup" and "Child cleanup"- Extending a maid makes it get destroyed by the parent maid on cleanup.
- Additionally if a child maid is destroyed separately then it gets removed from the parent maid's list of objects to clean, freeing up memory.
Using Maid as an add function
const maid = new Maid<{ SomeIndex: () => void }>();
maid(() => print("1"));
maid(() => print("2"), undefined, "SomeIndex");
maid.RemoveNoClean("SomeIndex");
maid.Cleanup(); // => "1" is printedAdding with Priority
const maid = new Maid();
maid.PriorityAdd(0, () => print("1"));
maid.PriorityAdd(1, () => print("2"));
maid.Add(() => print("3"), undefined, undefined, 2); // 2 is the priority
maid.Cleanup(); // prints out 1, 2, 3 in order. Normally this would print out in an unexpected order.- Lower priority numbers run first
- Tasks with priority run before tasks without priority
