Replies: 5 comments 3 replies
-
I would love to see RxJS's next move involve becoming a polyfill for the Web Platform's Observable, and rxjs then adding extra functionality similar to Lodash. The work done on version 8 is commendable, but the effort to support native observables is significant. Facilitating companies to prepare for this change would be advantageous. It would be more beneficial for the learning curve to be native, thanks to RxJS. Version 7 of RxJS is excellent, so there's no pressing need to introduce a major change only to transition again shortly. Thank you for all your hard work over the years. |
Beta Was this translation helpful? Give feedback.
-
I want to echo @Jordan-Hall's comment above. The comparison with Lodash makes a lot of sense. Really well written. Having used RxJS and Observables for almost a decade, I'm really happy to see this paradigm being baked in to the Web Platform. The faster we can facilitate this transition, the better it will be for the wider ecosystem to adopt these primatives. I am reminded of the transition from CoffeeScript to ES2015 and now the modern Javascript we have today. I foresee a similar future where these ideas will become mainstream, but it will require tooling and a lot of evangelizing. The polyfill approach can be a good start in this direction. |
Beta Was this translation helpful? Give feedback.
-
I'd like to add that I'm pretty sure that we could also create a new import '@rxjs/observable/polyfill';
const subscription = Observable.from([1, 2, 3])
.map(x => x + x)
.subscribe(console.log);
subscription.unsubscribe(); // ReferenceError: subscription is undefined
Observable.from([1, 2, 3])
.pipe(zipWith([4, 5, 6])); // Error: `pipe` is not a function import '@rxjs/observable/polyfill';
import '@rxjs/compat'; //<-- add this.
const subscription = Observable.from([1, 2, 3])
.map(x => x + x)
.subscribe(console.log);
subscription.unsubscribe(); // Happy again (but maybe reading as deprecated?)
Observable.from([1, 2, 3])
.pipe(zipWith([4, 5, 6])); // Happy again (maybe reading `pipe` as deprecated?) One issue is there is so much use of |
Beta Was this translation helpful? Give feedback.
-
Yeah that was my first thought was act as a polyfill in the interim and can have compat extension on top like lodash for pipe and ect. |
Beta Was this translation helpful? Give feedback.
-
This sounds awesome :) This would be useful to me. But you're saying the releasing this would be wasted work because an updated version that is compatible with native observables will be coming soon after? |
Beta Was this translation helpful? Give feedback.
-
Web platform Observables are on the horizon. Inclusion of web platform observables in Node is nearly a given, because they're part of EventTarget, which is in node.
RxJS 8 has been in alpha for a while, mostly because it's all volunteer work, and I've been spending a good amount of time working on the web platform observables, because it's very important.
I'm torn about whether to release a standalone RxJS Observable. Skip that and release a Web Platform polyfill observable, or something in the middle.
A Standalone RxJS Observable?
Part of the plan for RxJS 8 was to publish
@rxjs/observable
as a package, which would be a package that only includedObservable
and related, necessary types (Subscription
,Subscriber
, etc etc). That was always meant to be "The RxJS observable", complete withpipe()
et al, just without any of the operators (map
,filter
,concatMap
, etc).This was in response mostly to library authors who wished for widely-known, battle-tested RxJS observables, but didn't want to ship something that included access to all of the operators (which is honestly where most people tie themselves in knots if they don't know what they're doing).
Web Platform Observable
As stated above, the web platform is adopting observables as a means to help developers compose events. Which is really how observables shine. This observable will ship with a pretty robust set of methods:
map
,filter
,take
,drop
(skip),flatMap
(concatMap),switchMap
,scan
,tap
,catch
(catchError),takeUntil
,finally
(finalize),first
(firstValueFrom) andlast
(lastValueFrom), andObservable.from()
(our from).With the set of operations listed above, even yours truly will reach for RxJS less and less. And I couldn't be happier about that!*. RxJS will have become "lodash for events" in reality. As a beloved set utility functions that gets less and less useful as the platform advances.
RxJS MUST align with the platform
In the very long run, RxJS will stop publishing our own observables, and will migrate existing RxJS over to use the observables in the platform. RxJS 8 is already trying to head that direction, with the addition of the
rx()
function, the fact that oursubscribe
only takes one argument now (readying us to align with the web platform'ssubscribe
, which has a second argument that takes a configuration which includes anAbortSignal
for cancellation).Eventually, the RxJS codebase itself will be looking to see if what has been provided to any given operator is a platform observable or not, and relying on
Observable
being polyfilled globally.How Shall RxJS 8 move to beta?
RxJS 8 is bringing a LOT of value already. It's about 30% smaller than RxJS 7 (which itself was 45% smaller than RxJS 6). It's faster and lighter, and at least starting to prepare us for a world where Observable is ubiquitously available in global scope.
However, finding time to get the work done is always a challenge. I know that if I cut RxJS 8, and wait until RxJS 9 to support web platform observables, it might take quite a while, and I'll have done at least some work I'll have to throw away. So I'm left wondering:
Do we proceed with releasing a standalone version of RxJS observables (
pipe
method and all?) knowing that they're fundamentally different than the web platform observables that will be available very soon?Do we nix that idea, and instead release a standalone version of the Web Platform Observable, migrating RxJS itself over to this new era (and trying to do so in a way that breaks the fewest things? (i.e. supporting
Subscription
andAbortSignal
for a short time, etc). This would also involve making sure that RxJS observable had all of the methods that the web platform observable does, and deprecatedpipe
, which will not exist on the platform observable.Do we do something in the middle?
Other Considerations
Beta Was this translation helpful? Give feedback.
All reactions