Replies: 8 comments
-
We make our life complicated 😂 |
Beta Was this translation helpful? Give feedback.
-
The interaction with strings and the resulting inconsistent API with an exception case sounds like a too much of a cost to pay to go from |
Beta Was this translation helpful? Give feedback.
-
It's worth noting here that the TC39's async iterator helpers API will throw if an iterable primitive is returned (which is only really This goes back to my statement that most of the time when a |
Beta Was this translation helpful? Give feedback.
-
I also think I'd like to keep the current API. Cons outweight the Pros by far:
Both are related - Having an inconsistent API to do something special if
In a way, it's a good thing we get this exception. It's annoying because it's hard to debug (because of RxJS stack traces, but that's another topic), but it's actually good to receive this error to know that somewhere you messed up and you're returning a value you're not supposed to. If RxJS "swallows" this error through the new API, who knows what could happen on other streams that depend on it.
I usually just do |
Beta Was this translation helpful? Give feedback.
-
I prefer the current API. And for me, the pros are not really pros. I like the of() and the EMPTY to really see that we are working with observables and this is why we need a high order operator. it easier to read and easier for rxjs beginners to understand. Don't really like when things get too magical 😅 |
Beta Was this translation helpful? Give feedback.
-
I also vote for the current API. I prefer explicitness - it's better to see what the code does instead of having to figure out why it works a certain way |
Beta Was this translation helpful? Give feedback.
-
I see no compelling argument for auto-unwrapping here as it causes more unexpected behavior than it solves. I would prefer if that the |
Beta Was this translation helpful? Give feedback.
-
CORE TEAM: No for auto-unwrapping. But throwing when a |
Beta Was this translation helpful? Give feedback.
-
Since JavaScript introduced
Array#flatMap
, it follows the same sort of "auto-wrapping" (or unwrapping, depending on if you're a glass-is-half-empty person, I guess) that Promisethen
does, wherein it doesn't matter if you return an array or not.I'm not saying that we SHOULD do this work, I'm asking the community to comment on it.
It's definitely a breaking change we could only introduce in a major version.
Proposal
Any non-observable type. That is to say anything that isn't an
ObservableInput
(Arrays, iterables, AsyncIterators, promises, etc) would be automatically wrapped in operators likeconcatMap
,mergeMap
, et al.Prior Art
Array#flatMap
And inevitably this will work with Iterable and AsyncIterable (cc @mattpodwysocki) due to the iterator helpers proposal.
Promise#then, Promise#catch
Cons
1. Strings are iterables, and that gets confusing.
One issue I could see is strings confusing folks because they're iterables.
Array#flatMap
doesn't have this problem really because it doesn't auto-convert iterables.2. Adding new conversions may get harder.
During 7.x, we were able to start handling Async Iterable conversion in a non-breaking way. (Well, in retrospect it may have broken people that were trying to create an
Observable<AsyncIterator<T>>
or something, but that never came up, and we considered it to be too far fetched).If another type gets added down the road, let's say they add "signals" to the platform in some sense, we'd need a major release to start handling them appropriately if we wanted to convert them automatically.
Pros
1. There would be no more "You provided an invalid object where a stream was expected" errors.
Because everything would just pass through. If you get an error, it should be thrown where you tried to use an incorrect type.
2. Eliminates most of the need for
of
.Which is a notably ugly API. Honestly most people could get around
of(1)
on the cheap by just using[1]
, but whatever.3.
void
could meanEMPTY
at this point.I think this means a bit less "magic" that people need to know about RxJS. But then again, another way to look at it is that
void
meaning "empty" is more magical.Beta Was this translation helpful? Give feedback.
All reactions