Skip to content

feat: SustainModel:Observe() #554

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

Open
wants to merge 2 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
27 changes: 26 additions & 1 deletion src/transitionmodel/src/Shared/Sustain/SustainModel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local require = require(script.Parent.loader).load(script)

local BaseObject = require("BaseObject")
local Maid = require("Maid")
local Observable = require("Observable")
local Promise = require("Promise")
local Signal = require("Signal")

Expand Down Expand Up @@ -95,6 +96,30 @@ function SustainModel:PromiseSustain(doNotAnimate: boolean?)
return self:_promiseSustained()
end

--[=[
Observes the current state of the SustainModel.
Emits true when sustaining and false otherwise.

@return Observable<boolean>
]=]
function SustainModel:Observe()
return Observable.new(function(sub)
if not self.Destroy then
warn("[SustainModel.Observe] - Connecting to dead SustainModel")
sub:Complete()
return
end

local connection = self.SustainChanged:Connect(function(isSustained)
sub:Fire(isSustained)
end)

sub:Fire(self._isSustained)

return connection
end)
end

function SustainModel:_promiseSustained()
if not self._isSustained then
return Promise.resolved()
Expand Down Expand Up @@ -142,4 +167,4 @@ function SustainModel:_executeSustain(doNotAnimate: boolean?)
end


return SustainModel
return SustainModel