-
-
Notifications
You must be signed in to change notification settings - Fork 443
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
Changes from all commits
68c66f0
62fd6af
40c0647
606e2b3
a71b8ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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) | ||
|
||
if type(onEnd) == 'function' then | ||
self.private.onEnd = onEnd | ||
end | ||
Comment on lines
+99
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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 notfunction
. But let see what linden got!