Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning the destructor from Trove:BindToRenderStep #206

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions modules/trove/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type Trove = {
Clone: <T>(self: Trove, instance: T & Instance) -> T,
Construct: <T, A...>(self: Trove, class: Constructable<T, A...>, A...) -> T,
Connect: (self: Trove, signal: SignalLike | RBXScriptSignal, fn: (...any) -> ...any) -> ConnectionLike,
BindToRenderStep: (self: Trove, name: string, priority: number, fn: (dt: number) -> ()) -> (),
BindToRenderStep: (self: Trove, name: string, priority: number, fn: (dt: number) -> ()) -> () -> (),
AddPromise: <T>(self: Trove, promise: T & PromiseLike) -> T,
Add: <T>(self: Trove, object: T & Trackable, cleanupMethod: string?) -> T,
Remove: <T>(self: Trove, object: T & Trackable) -> boolean,
Expand Down Expand Up @@ -347,8 +347,10 @@ end
@param name string
@param priority number
@param fn (dt: number) -> ()
@return () -> ()
Calls `RunService:BindToRenderStep` and registers a function in the
trove that will call `RunService:UnbindFromRenderStep` on cleanup.
trove that will call `RunService:UnbindFromRenderStep` on cleanup. It
also returns the registered function for cleanup with `Trove:Remove`.

```lua
trove:BindToRenderStep("Test", Enum.RenderPriority.Last.Value, function(dt)
Expand All @@ -362,10 +364,11 @@ function Trove.BindToRenderStep(self: TroveInternal, name: string, priority: num
end

RunService:BindToRenderStep(name, priority, fn)

self:Add(function()
local destructor = function()
RunService:UnbindFromRenderStep(name)
end)
end
self:Add(destructor)
return destructor
end

--[=[
Expand Down