question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Rx.Observable.from` does not properly handle `NodeList`

See original GitHub issue

Consider the following code:

const buttons = document.querySelectorAll('.btn');

const button$ = Rx.Observable.from(buttons);
const button2$ = Rx.Observable.from(buttons);

button$.subscribe(x => console.log('observer 1 ', x)); // emit
button$.subscribe(x => console.log('observer 2 ', x)); // nothing
button2$.subscribe(x => console.log('observer 3 ', x)); // emit

Rx.Observable.from should result in a cold observable that emit the same list each time it is subscribed. However, in this example the source is a NodeList and the second subscription does not emit.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Doruscommented, Nov 3, 2017

@cartant Yes i did know that, but thanks for the suggestion anyway. It’s exactly what i suggested @mocheng on gitter 3 november 2017 12:14 as he’s the one that came up with this scenario.

@kwonoj No prob about the confusion, at least it kept the issue active and quickly resolved 😃

1reaction
cartantcommented, Nov 3, 2017

@Dorus You most likely already know this, but you can work around the problem in version 5 using defer:

const button$ = Rx.Observable.defer(() => Rx.Observable.from(buttons));
Read more comments on GitHub >

github_iconTop Results From Across the Web

Observable | RxJS API Document - ReactiveX
Creates an Observable that emits events of a specific type coming from the given event target. Creates an Observable from an API based...
Read more >
Bridging To Events | RxJS - Javascript library for functional ...
Every time an event is raised, an onNext message will be delivered to the observable sequence. You can then manipulate event data just...
Read more >
Property 'from' does not exist on type 'typeof Observable ...
I updated my angular 5.2.10 project to angular 6. I did step by step https://update.angular.io/ , everything is OK unless Observable.
Read more >
fromEvent - RxJS
Just as in case of NodeList it is a collection of DOM nodes. Here as well event handler function is installed and removed...
Read more >
How to Create Observables in RxJS - Better Programming
RxJS is the most popular framework for functional reactive programming (FRP) in JavaScript. Angular is entirely built around RxJS and FRP ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found