Skip to content
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

The Observable created with of and from has a different behavior when use repeatWhen. #2802

Closed
keifergu opened this issue Aug 21, 2017 · 5 comments

Comments

@keifergu
Copy link

RxJS version: 5.0.0-beta.12

Code to reproduce: https://jsfiddle.net/keifer/gyyv329f/

Expected behavior:

from:1
from:1
from:1
...

Actual behavior:

from:1

Additional information:
When I use the of operator to create an Observable, the behavior is right. But when I do it with from, I think the result is wrong.

@kwonoj
Copy link
Member

kwonoj commented Aug 21, 2017

of and from are different api for handling input - from should supply Array-like object. Due to string is considered as array-like, supplying 1 doesn't raises compilation error but it should be [1] instead to achieve desired behavior.

For example, if you do

Rx.Observable.from('123').map((x) => x + 'x').subscribe(console.log.bind(console));

output will be 1x, 2x, 3x

while

Rx.Observable.of('123').map((x) => x + 'x').subscribe(console.log.bind(console));

will be 123x.

@kwonoj kwonoj closed this as completed Aug 21, 2017
@keifergu
Copy link
Author

@kwonoj thanks for your comment,and sorry to reply to you so late.I had created a new fiddle to explain my question.

When we use repeatWhen, the observable that created with Observable.from(<String>) or Observable.from(<Array>) have a different behavior.The <String> observable will only repeat once. But the <array> will repeat at intervals of 2000ms.You can reproduce the problem in that fiddle.

Looking forward to your reply.

@paulpdaniels
Copy link
Contributor

@kwonoj @keifergu might have a point it looks like there is some inconsistent behavior here. The IteratorObservable generates the iterator during construction rather than during subscription (see here). Was there a behavioral reason that this needed to be done?

@kwonoj
Copy link
Member

kwonoj commented Aug 24, 2017

@paulpdaniels check #2497 for those.

@lock
Copy link

lock bot commented Jun 6, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants