-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Support Symbol.observable #677
Comments
Possible streams to export:
Reading streams:
@benjamingr what is your use case? |
I want to use mobx observables inside Rx operators like: someRx.switchMap(() => this.someMobX)... And have var autocomplete = toRx(mobxForInput).
filter(Boolean).
switchMap(value => fetch("/api/"+value)).
toMobX() For autocomplete for example. In addition it would be great if the other way around worked too: @observable foo = someRxStream; // when someRxStream emits a value, mobx change to it |
The implementation is basically to add a interface IObserver {
next(value): void;
error(error): void;
complete(value): void;
}
interface ISubscription {
unsubscribe(): void;
}
interface IObservable {
subscribe(observer: IObserver): ISubscription
[Symbol.observable](): IObservable;
} So a minimal version of this would be as simple as: SomeObject.prototype[Symbol.observable] = function () {
return {
[Symbol.observable]() { return this; }
subscribe(observer) {
observer.next('hello world');
observer.complete();
return {
unsubscribe() { console.log('teardown here'); }
};
}
}; I hope that helps. |
Also, worth noting... this is the widely used current API. As the proposal in the TC39 changes (slowly), this is liable to change. However all changes that I know of should be something that supports backwards compatibility. |
@Blesh Never mind, found it |
@benjamingr Figured these conversions methods are a better fit for |
@mweststrate since Optimally, I'd like: @observable debouncedClickDelta = fromEvent(...).filter(...).map(...) So that observable unwraps things with Additionally, if we support Rx.Observable
.fromEvent(button, "click")
.map(e => computed(user.firstname + user.lastName))
.distinctUntilChanged()
.scan(nameChanges => nameChanges + 1, 0)
.subscribe(nameChanges => console.log("Changed name ", nameChanges, "times")) Which is arguably a lot cleaner. |
@benjamingr I can live with the second example (note that it would be But for the first example, how should one ever dispose the stream? |
@mweststrate the same way you dispose any other observable? One MobX observable subscribing to one Rx observable. |
Would a clarification help? |
@benjamingr for the disposing in the first example; yes; the subscription to the observable stream should be disposed at some time. But There is the notion of |
I don't mind if instead of: @observable debouncedClickDelta It's: @computed debouncedClickDelta Or something like that. |
ping |
@benlesh what is Rx currently doing? Is |
@benjamingr we're still using Symbol.observable. It's used by a lot of libraries now, it would take a lot of work and coordination to swing it to something else. |
I suppose this is kinda outdated and nobody seems interested in implementing it. Let's close it and I will reference #2327 just in case it wants to happen there. |
Not sure about exact api yet. Probably similar to
observe
? Or a utility that takes an expression that is tracked, and it's output can be subcribed to?The text was updated successfully, but these errors were encountered: