Forest Logo
search
package_2

keeper

By @averyark

Roblox

Mirrored from Wally

Keeper

Keeper is a Trove-style utility for tracking and cleaning up objects, now with optional keys for grouped cleanup.

Install (Wally)

[dependencies]
Keeper = "averyark/keeper@1.9.0"

Basic Use

local Keeper = require(path.To.Keeper)

local trove = Keeper.new()
local part = Instance.new("Part")

trove:Add(part, "effects")
trove:Clean("effects")

Keys and cleanup methods

Add(object, key?, cleanupMethod?) uses its second argument as a group key. Pass nil for the key when supplying a custom cleanup method without a group:

local resource = { Release = function(self) print("Released") end }
trove:Add(resource, nil, "Release")
-- Or use a group:
trove:Add(resource, "effects", "Release")

Keys can be any non-nil value, including false. Multiple objects can share a key.

CallBehavior
Clean(key)Clean every entry with that key.
Clean()Clean all keyed and unkeyed entries.
Remove(object, key?)Remove and clean one matching entry, optionally filtered by key.
Remove(nil, key)Remove and clean every entry with that key.
Pop(object, key?)Stop tracking one matching entry without cleaning it.
Pop(nil, key)Stop tracking every entry with that key without cleaning them.
WrapClean(key?)Return a callback that cleans the given group, or everything if omitted.
Destroy()Clean everything.

Remove and Pop return whether any entries were removed. With neither an object nor a key, they return false. A missing group is a no-op. nil in Clean and WrapClean means all entries; it does not select only unkeyed entries.

Passing a key as the object, as in Remove("effects"), throws an error. Use Remove(nil, "effects") or Clean("effects") instead.

Tests

Run lune run test/run.luau with Lune installed. The runner supplies a minimal Roblox service stub for the group tests; it does not exercise Roblox services.

Package Details

Install command (Click to copy)


Version

1.10.2

License

MIT

check_circle

Safe for commercial use

Automated license review — not legal advice.