Observables cannot be passed between window contexts.
See original GitHub issueRxJS version: 5.4
Code to reproduce:
if (window.opener) {
window.myObservable = window.opener.myObservable;
} else {
window.myObservable = Rx.Observable.of(1, 2, 3);
window.open(location.href);
}
window.myObservable
.switchMap(function(x) {
return Rx.Observable.of(x);
})
.subscribe(function(x) {
console.log(x);
});
Expected behavior: Both parent and child window should print 1, 2, 3 to the console.
Actual behavior:
The child window throws an exception because myObservable
from the parent window’s context cannot be identified as an Observable in the child window’s context.
Additional information:
The issue is caused by a reliance on instanceof
for determining if an object is an Observable which fails for objects passed between javascript contexts. Instead, a more robust solution would test for the shape of an Observable, perhaps using a type guard similar to isPromise
Issue Analytics
- State:
- Created 6 years ago
- Comments:20 (13 by maintainers)
Top Results From Across the Web
How to pass results between chained observables
In order to achieve this you can write context depending version of map , contentMap , mergMap operators so that the final solution...
Read more >Troubleshooting Embedding
If you have a cell that runs an update method, make sure the cell is named and references the cell it is modifying....
Read more >Using observables to pass values
An observable can deliver multiple values of any type —literals, messages, or events, depending on the context. The API for receiving values is...
Read more >Observable
Observables are able to deliver values either synchronously or asynchronously. What is the difference between an Observable and a function? Observables can " ......
Read more >Observable | RxJS API Document
combineLatest combines the values from all the Observables passed as arguments. This is done by subscribing to each Observable in order and, whenever...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If it can be of any help, I couldn’t make it work with
But I got it working with
Ah good to see that I was not just going crazy 😜 .
I think this is related to #2489 too, since things would get more complicated if we do this:
at that point
switchMap
is from context B and for everything done during the setup phase of the Observable it can only assume valid what is from context B, while it is asked to work on something from context A, throughpipe
.