-
-
Notifications
You must be signed in to change notification settings - Fork 126
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
now() returns not a relevant time if accessed from outside a reactive context #40
Comments
See this example: https://jsfiddle.net/pwcv8xsu/1/ Does that help you out? |
@mattruby No, because getter "time" is used not only inside reaction(autorun). |
@rasentry we're getting a little funky here, but you'll need to use |
Mobx will try to clean up |
As I think it is not appropriate solution, because I need to take care about disposer. |
I think that example is using reactions. If you use `reaction` or `autorun`
mobx will take care of itself (for the most part). You're asking to hit a
computed outside of a reaction, correct?
…On Thu, Feb 16, 2017 at 12:30 PM, rasentry ***@***.***> wrote:
As I think it is not appropriate solution, because I need to take care
about disposer.
In my project I use code from example from here
https://mobx.js.org/refguide/extending.html
and there is no need disposer.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#40 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAIrcusAmymdIrgD_BSXIl-vfY6UkAL4ks5rdJWtgaJpZM4MCtzo>
.
--
-Matt Ruby-
[email protected]
|
Yes I use my gette inside and outside reaction. Inside reaction it works as designed, but when no reaction on this getter it returns old (cached) value. |
I think the problem is here https://github.com/mobxjs/mobx-utils/blob/master/src/from-resource.ts#L106 if (this.atom.reportObserved()) {
return this.currentDateTime;
} else {
// apparantly getTime was called but not while a reaction is running.
// So, nobody depends on this value, hence the onBecomeObserved handler (startTicking) won't be fired
// Depending on the nature
// of your atom it might behave differently in such circumstances
// (like throwing an error, returning a default value etc)
return new Date();
} |
I think the only way to get it working the way you want is to use
`keepAlive`. I'm pretty sure it's going to end up being equivalent to any
other solution you'd implement. If you built your own timer, you'd still
have to dispose of the interval.
I should note, that this is my first time playing with keepAlive. I
haven't had to use it in production yet.
…On Thu, Feb 16, 2017 at 12:36 PM, rasentry ***@***.***> wrote:
Yes I use my gette inside and outside reaction. Inside reaction it works
as designed, but when no reaction on this getter now inside it returns old
value.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#40 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAIrcgRtilEJ2z1BhmV9wFrwr0S9HDl9ks5rdJcbgaJpZM4MCtzo>
.
--
-Matt Ruby-
[email protected]
|
Mm I think this can be fixed by checking if now () is being accessed from
inside a derivation. Mobx.extras probably has some funky method to detect
that. If the invocation isn't being tracked we can just return Date.now
Op do 16 feb. 2017 19:41 schreef Matt Ruby <[email protected]>:
… I think the only way to get it working the way you want is to use
`keepAlive`. I'm pretty sure it's going to end up being equivalent to any
other solution you'd implement. If you built your own timer, you'd still
have to dispose of the interval.
I should note, that this is my first time playing with keepAlive. I
haven't had to use it in production yet.
On Thu, Feb 16, 2017 at 12:36 PM, rasentry ***@***.***>
wrote:
> Yes I use my gette inside and outside reaction. Inside reaction it works
> as designed, but when no reaction on this getter now inside it returns
old
> value.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#40 (comment)>,
> or mute the thread
> <
https://github.com/notifications/unsubscribe-auth/AAIrcgRtilEJ2z1BhmV9wFrwr0S9HDl9ks5rdJcbgaJpZM4MCtzo
>
> .
>
--
-Matt Ruby-
***@***.***
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#40 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABvGhHnMU40Pp4g3UcsBLXz9DcJZ4-6sks5rdJg9gaJpZM4MCtzo>
.
|
@mweststrate As a temporary solution it is good, but I think now() should work like a "normal" Date.now(), isn't it? |
Pushed a fix, will be part of next release |
When I use now in computed value and use it outside reaction it returns not relevant time.
see https://jsfiddle.net/pwcv8xsu/
The text was updated successfully, but these errors were encountered: