-
Notifications
You must be signed in to change notification settings - Fork 330
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
Property current value handling in case of re-activation #770
Comments
I’m not sure about Bacon internals, but my guess is that a |
To me it seems that there are genuine cases for all three alternatives A) retain "stale" value / current behavior: the previous seen value may be the best initial value, to be updated when new data can be fetched. E.g. stock ticker with a timestamp, chat conversation history, web shop product catalog. Then there are also the Properties that are not just stream.toProperty() but built on an arbitrary mix of inputs. I'm actually unsure which property methods will cause state values to be retained even if their sources did drop the stale value. But I'd expect the resultant property to drop stale values if any of its sources so does. Also I'd hope to have an explicit |
I hope that I understand the proposal and can express my observations adequately, otherwise please correct or ask me to clarify. Considering
|
Current behaviour or Properties when created with stream.toProperty() is that is a property is deactivated (all subscribers removed), it will maintain its current value while not connected to the underlying stream. This means that upon re-activation it will emit the possibly stale current value to it's new subscribers.
Here's a running example: https://codesandbox.io/s/property-with-eventstream-4h4sb?file=/src/App.tsx
This behavior is ok for some cases, but there are cases where you may prefer something else.
In some cases the current value could be obtainable with a single synchronous call. Use window scroll position for example. How to do that in Bacon.js? Well you can but it's not obvious. Here's how: https://codesandbox.io/s/topropertywithinitvaluefn-l0n8z?file=/src/App.tsx
Yet sometimes there's no feasible way to fetch a new value synchronously and you might prefer just not emitting a stale value, but instead emitting nothing until a fresh value can be provided. Also this is a simple solution in Bacon.js, which is far from obvious if you're unfamiliar with the library internals. Like this: https://codesandbox.io/s/topropertydropstalevalues-504gv
I'm considering whether these alternatives make sense to you as well and how should the API be shaped? This might be something for the 4.0 release.
In short, here are the implementations:
The text was updated successfully, but these errors were encountered: