-
Notifications
You must be signed in to change notification settings - Fork 90
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
Subscribe callback with current value of stateful observables #190
Comments
I would expect |
Thanks. That's my expectation too. I'd like to be compliant with any specs, or at least consistent with other libraries. |
@brianmhunt we've (I've) been dragging our feet with this for ~2 years with MobX - I think we can agree on that semantic for it. cc @mweststrate |
…tyle subscribe So when a TC39 style `subscribe` call is made, we trigger with the current value immediately, contrasting with the prior behaviour - namely triggering only on changes to the state. tc39/proposal-observable#190
I would expect only That being said, personally I don't care that much, as long as it is standardized :-D. |
The subscription could provide an option e.g. something like this:
|
@mweststrate I think this is similar to a |
@mbest any thoughts on this? |
I think it should mirror the Knockout |
This feels off-topic to me. The Observable pattern and how Knockout makes use of it are separate topics, and only the former is germane here. It's common for stateful Observables (e.g. Subjects) to emit the last known value to new subscribers. However, that's a decision to be made at the producer level (probably Knockout in this case), not one that needs to be discussed here. |
I don't understand where this is coming from - using To be honest - as far as I'm aware following this repo for 3+ years we never had this discussion about I will defer to Jafar and Mark about whether or not they consider this discussion useful at the moment though. |
* Initial support of TC39 Observable subscriptions * tko.observable) Trigger immediately with current with TC39 `{next}`-style subscribe So when a TC39 style `subscribe` call is made, we trigger with the current value immediately, contrasting with the prior behaviour - namely triggering only on changes to the state. tc39/proposal-observable#190 * jsx) fix out-of-order observable insertion * jsx) Fix arrays of new nodes not having context applied * provider/native) Add a provider that has “pre-compiled” binding handler arguments This will be used by the JSX utility. * component/jsx) Support observables for Component jsx templates Now JSX binding arguments are known at the compile-time, so this ought to work: ```js get template () { return <div ko-text={this.someValue}></div> } ``` * jsx) Add support for bindings directly referenced in JSX Sample: ```html <component x={alpha}></component> ``` … will be given `params={x: alpha}` * provider/native) Fix failure when node doesn’t have `NATIVE_BINDINGS` * component/jsx) re-apply bindings to top-level templates * tko.bind) Fix regression with `onValueUpdate` not working @ctcarton * tko.observable/computed) Have TC39 subscriptions fire immediately for observable/computed * jsx) Fix insert of array appending instead of inserting
For the moment, in tko/knockout 4 alpha I've set up ko observables to emit their current state whenever a TC39-compliant I can be persuaded to change this, particularly before we end the alpha stage, but I wanted to the concept merged — even if not in its final form. |
@brianmhunt what if initial state is undefined? Does that still emit value? |
@dy undefined is still a value, so I would expect it to be have the same as any other value. |
@brianmhunt I meant what if initial value is not defined, ie. value is not provided for init? That is different from |
@dy You mean if the value of the observable had never been set? I think the behaviour most would expect is to emit an |
I remember using that somehow implementing combined observables, not relevant anymore. |
It's not clear (and perhaps not defined) what should happen when stateful observables like those in Knockout and mobx and others should do when
.subscribe
is called.I.e. what should happen in this sequence:
Should the output be
abc def
or justdef
?I ask in particular because I'm adding TC39 support to Knockout.
The text was updated successfully, but these errors were encountered: