-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Strange behaviour of Observable.of([x]).map #1140
Comments
Should have mentioned this was tested with |
@chrisprice ... currently there are optimizations for ScalarObservables. A ScalarObservable is any Observable that gives you a single, synchronous value. (in other words It's a powerful optimization, but it's up for debate, for sure.
Generally, you shouldn't be creating side-effects in your |
In short...
|
Thanks for the explanation, that does explain the behaviour I saw. The snippet I discovered this in caused me to pull my hair out - Rx.Observable.of([
{z: 1}
])
.map((x) =>
x.map((y) => (y.z += 'A', y))
)
.subscribe((x) => console.log(x)) Which logged out -
Now I agree that's an odd thing to be doing (I was just hacking some test data) and I also agree that map functions shouldn't contain side-effects, but it was totally unexpected behaviour! |
Actually I've been thinking about this and I'm not sure whether your explanation covers why the |
Yeah, there is a bug apparently: let source = Rx.Observable.of(1)
.map((x) => {
console.log('hit');
return x;
}); logs: "hit"
"hit" Flagging this as a bug. However it should go away if these optimizations are removed with #1142 |
- remove usage of ScalarObservable for optimization - implementation of ScalarObservable still remain for possible further usage closes ReactiveX#1142, ReactiveX#1150, ReactiveX#1140
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I have a use case for creating an observable of arrays and came across some odd behaviour. The map function is invoked twice when using
Observable.of(x)
but not when usingObservable.from([x])
. Is this expected?However, swapping
Observable.of([42])
forObservable.from([[42]])
as below, doesn't trigger the failure.The text was updated successfully, but these errors were encountered: