You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes I run into a situation where I need to reset a signal's state to some empty or default value when the signal is re-started. This is usually because the same signal is used to hold data for e.g. a currently selected product, as the user switches between products, and it usually involves asynchrony, e.g. from network requests.
This will emit 0 every time that resettingStream is started.
However, we don't really have the same functionality for signals. Yes, we have composeChanges, but that only works for subsequent events, it's not suitable for general-purpose resetting logic (and it also introduces streams into a signal pipeline, which may have other issues related to re-syncing).
Naming could be a problem. We already use stream.startWith(initial) to convert streams to signals. This operator is very old and may even be in my laminar video, so I probably wouldn't want it to subtly change meaning.
Similar to debgugging methods, perhaps we could have a single method used like signal.lifecycle(_.restartWith(0)), but I don't really know what other hooks could be useful. Perhaps _.stopWith(value) to unload big data structures from memory when the signal is stopped? Nobody would see the new value event until the signal is restarted. We proooobably can implement that.
Welp, not sure yet. Just writing this down in case anyone wants to share similar needs or solutions.
The text was updated successfully, but these errors were encountered:
Sometimes I run into a situation where I need to reset a signal's state to some empty or default value when the signal is re-started. This is usually because the same signal is used to hold data for e.g. a currently selected product, as the user switches between products, and it usually involves asynchrony, e.g. from network requests.
For streams, we at least have this:
This will emit
0
every time thatresettingStream
is started.However, we don't really have the same functionality for signals. Yes, we have
composeChanges
, but that only works for subsequent events, it's not suitable for general-purpose resetting logic (and it also introduces streams into a signal pipeline, which may have other issues related to re-syncing).I think we could have operators like:
Naming could be a problem. We already use
stream.startWith(initial)
to convert streams to signals. This operator is very old and may even be in my laminar video, so I probably wouldn't want it to subtly change meaning.Similar to debgugging methods, perhaps we could have a single method used like
signal.lifecycle(_.restartWith(0))
, but I don't really know what other hooks could be useful. Perhaps_.stopWith(value)
to unload big data structures from memory when the signal is stopped? Nobody would see the newvalue
event until the signal is restarted. We proooobably can implement that.Welp, not sure yet. Just writing this down in case anyone wants to share similar needs or solutions.
The text was updated successfully, but these errors were encountered: