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

fix(timer): restart can prevent executing onEnd function #667

Closed
wants to merge 5 commits into from
Closed
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
10 changes: 8 additions & 2 deletions imports/timer/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
---@class OxTimer : OxClass
---@field private private TimerPrivateProps
---@field start fun(self: self, async?: boolean) starts the timer
---@field restart fun(self: self, async?: boolean, onEnd?: boolean | function) restart the timer
---@field forceEnd fun(self: self, triggerOnEnd: boolean) end timer early and optionally trigger the onEnd function still
---@field isPaused fun(self: self): boolean returns wether the timer is paused or not
---@field pause fun(self: self) pauses the timer until play method is called
Expand Down Expand Up @@ -92,8 +93,13 @@ function timer:isPaused()
return self.private.paused
end

function timer:restart(async)
self:forceEnd(false)
function timer:restart(async, onEnd)
self:forceEnd(not not onEnd)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this double not flip is to handle the function case, but I think there is a better way to handle this if we do end up wanting the onEnd to accept a function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah just to pass it as boolean and not function. But let see what linden got!


if type(onEnd) == 'function' then
self.private.onEnd = onEnd
end
Comment on lines +99 to +101
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think dynamically adding an onEnd function during a reset makes a lot of sense. What would this use case actually be?

@thelindat what are your thoughts on allowing an onEnd function to be added during a reset? Personally it feels like a really confusing user experience / flow.


Wait(0)
self.private.currentTimeLeft = self.private.initialTime
self.private.startTime = 0
Expand Down