-
Notifications
You must be signed in to change notification settings - Fork 699
Add stop(), start(), and restart() methods to Timer #8821
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
base: master
Are you sure you want to change the base?
Conversation
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.
Thanks,this looks good.
The only missing thing I can see is the documentation.
I've also added comments about adding extra tests for Timer in sub components.
Not sure how testing should be done for the interpreter here.
The JS scripts take care of it.
@@ -319,6 +319,7 @@ pub struct Timer { | |||
pub interval: NamedReference, | |||
pub triggered: NamedReference, | |||
pub running: NamedReference, | |||
pub element: ElementRc, |
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 believe we need to keep a reference to the original element only to be able to lookup its index later as it is part of the .restart() function.
I'm wondering if there is a better way. I could think of storing the index within the Element
Or rewriting the call to RestartTimer to have the timer index. But that seems dangerous.
I'm worried that the timer could be wrong after some inlining steps or something like that though. But it might be fine.
out property <string> result1; | ||
out property <string> result2; | ||
|
||
// multiple timers so we can ensure that the index resolution is working correctly |
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.
👍
Could you add an extra timer in another component?
Like add some component such as
component ComponentWithTimer {
timer-a := Timer { ... }
if true: Rectangle { // Make sure it works in condition.
timer-b := Timer {
running: false;
interval: 3s;
triggered => { self.stop(); root.triggered("b") }
init => { timer-b.start() }
}
}
callback trigerred(string); // called from the triggered callback of the timers
function ... // to start and restart timer-a
}
And then use that component twice, from the Window.
Just to make sure that nothing fishy happens when the timer is in a sub component.
This code is just an example feel free to be creative ;-)
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.
Awesome work, looks very clean to me. I've found one potential issue - see comment inline. I'll defer to Olivier for the final approval :)
@@ -319,6 +319,7 @@ pub struct Timer { | |||
pub interval: NamedReference, | |||
pub triggered: NamedReference, | |||
pub running: NamedReference, | |||
pub element: ElementRc, |
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.
My guts feeling is that this should perhaps be an ElementWeak
instead of an ElementRc
.
Adds timer start(), stop(), and restart() methods. Closes #7476. Not sure how testing should be done for the interpreter here.