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

Re-evaluate signal's current value when restarting signal #43

Closed
raquo opened this issue Nov 22, 2020 · 0 comments
Closed

Re-evaluate signal's current value when restarting signal #43

raquo opened this issue Nov 22, 2020 · 0 comments
Labels
design hard problem need to find time https://falseknees.com/297.html

Comments

@raquo
Copy link
Owner

raquo commented Nov 22, 2020

val state =  Var(0)
val x10signal = state.signal.map(_ * 10)
val x100signal = x10signal.map(_ * 10)

Currently, when you first start x100signal, it initializes its initial value (not a typo – signals' initial values are lazy) by pulling the current value of x10signal, which initializes the initial value of x10signal by pulling state.signal's current value. However, if afterwards you stop x100signal, then after some time start it again, this pulling-current-value chain will not happen, x100signal will simply start listening to new x10signal updates from this point on. This means that if state was updated while x100signal was stopped, x100signal will not receive this update when it's started again.

This is documented behavior – observables are lazy, so you shouldn't stop the ones you care about – but it would be more useful if x100signal could recursively pull its parent's current value not just when initializing the signal's initial value, but every time it's started.

This would have convenient practical effects in Laminar when re-mounting unmounted elements – those would be brought up to date when they're re-mounted.

However, very importantly, this measure can't cancel out laziness per se, and specifically this can not possibly replay the EventStream events that fired while the signal was stopped, so we will not be able to pull an updated current value for signals that depend on event streams, such as stream.foldLeft(...) or stream.startWith(...).

This caveat will make undesired behavior more rare, but more specialized and harder to debug. However, it is probably a good tradeoff, since it should be more obvious that any events you've missed will not be re-emitted, than how your signal won't pull a parent's current value when it's reactivated.

gitter context

@raquo raquo added enhancement New feature or request design need to find time https://falseknees.com/297.html labels Nov 22, 2020
vic added a commit to vic/Airstream that referenced this issue Jan 27, 2021
This branch changes Signal.onStop to make it forget its
internal memory when all observers have been removed. Causing it
to re-compute its "initialValue" again if the Signal is re-started.

This way, dependent signals (eg, MapSignal) can ask their parent
signal for the latest value upon restarting, and elements that read
these dependent signals can now observe the correct state when re-mounted.

Fixes raquo#43
davoclavo pushed a commit to deal-engine/Airstream that referenced this issue Mar 18, 2021
This branch changes Signal.onStop to make it forget its
internal memory when all observers have been removed. Causing it
to re-compute its "initialValue" again if the Signal is re-started.

This way, dependent signals (eg, MapSignal) can ask their parent
signal for the latest value upon restarting, and elements that read
these dependent signals can now observe the correct state when re-mounted.

Fixes raquo#43
davoclavo pushed a commit to deal-engine/Airstream that referenced this issue Mar 19, 2021
This branch changes Signal.onStop to make it forget its
internal memory when all observers have been removed. Causing it
to re-compute its "initialValue" again if the Signal is re-started.

This way, dependent signals (eg, MapSignal) can ask their parent
signal for the latest value upon restarting, and elements that read
these dependent signals can now observe the correct state when re-mounted.

Fixes raquo#43
@raquo raquo removed the enhancement New feature or request label May 5, 2021
fabianhjr pushed a commit to fabianhjr/Airstream that referenced this issue May 18, 2021
This branch changes Signal.onStop to make it forget its
internal memory when all observers have been removed. Causing it
to re-compute its "initialValue" again if the Signal is re-started.

This way, dependent signals (eg, MapSignal) can ask their parent
signal for the latest value upon restarting, and elements that read
these dependent signals can now observe the correct state when re-mounted.

Fixes raquo#43
raquo added a commit that referenced this issue Dec 4, 2021
 - This is a big change to fix #43
 - Not quite complete yet, still need to work on various timing streams
 - Also removed some Future-related stuff that I don't want to support anymore
@raquo raquo closed this as completed in 5d4b629 Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design hard problem need to find time https://falseknees.com/297.html
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant