-
Notifications
You must be signed in to change notification settings - Fork 627
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
Passing context info in onTick function #47
Comments
Hmm. I can see this being useful. The tradeoff is that you do not get to call It will default to calling the Thoughts? |
It seems to be a nice feature that the oncomplete method be allowed to have a specific context within which to execute (GH-47). Signed-off-by: Nick Campbell <[email protected]>
I've got one other feature I want to work out before pushing a new version. Once that is done I'll publish. For now you can use the code from master to accomplish what you want. Also, I just noticed that I called it |
This has been published to npm in v1.0.1. |
Great ... thanks... |
Hello. My code is using 1.3.0 version and I'm not able to send a custom context to the onTick function. If I don't send any context, the this.stop() method cannot be called neither because stop is not a function... Any ideas? thnks. |
@Danielv3 do you have a code sample you're using? |
I solved the issue. You need to use "function() {}" instead of the newly arrow functions "() => {}" in order to be able to use "this" as context. In the newer arrow format you don't receive the context in this. |
I also had a similar issue as @Danielv3 while using a fat arrow function within a class on the onTick method. Because fat arrow functions get their "this" value from their enclosing lexical context and not the actual context they are within you don't actually get the cronJob attached to the "this" keyword inside the onTick function. Only a suggestion, but with more and more people using arrow functions by default it might be a good idea to add something to the docs about this. Arrow functions should not be used for the onTick method, only regular javascript functions. |
@charliecode I added a note, thanks for the suggestion. |
Is there any plans to support arrow functions or are there any particular reasons against them? onTick(this) |
I'd review a pr for this if you're interested and able, but at the moment
I'm too busy with other work to focus on it.
…On Tue, Apr 23, 2019, 10:40 AM Sascha ***@***.***> wrote:
Is there any plans to support arrow functions or are there any particular
reasons against them?
It should be easy to pass the this context as a parameter to arrow
functions.
E.g.
onTick(this)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#47 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAPJF2FXGAPHAER4ABCNLTPR4NUJANCNFSM4ABFUB2Q>
.
|
I'll have a look into it. |
its more easy to use .apply or .call and pass the correct this param |
We need to pass context info in onTick function the way this is implemented in setInterval, any support for this.
The text was updated successfully, but these errors were encountered: