Today I've seen a strange problem when using RxJS. Please help me inspect it.
The problem I am working on is: "Given an array of image URLs, load and append all images to a div."
All the code snippets to demonstrate is here:
At the beginning, I used the first snippet
.
However, Rx.Observable.prototype.flatMap
sometimes puts the images in wrong order (this behavior is noticed in the documentation). So, I changed to use concatMap
(second snippet
).
This time, only the first image is loaded. I took some time inspect the problem. I doubt that event load
is not trigged from image
. But the most confusing situation is that when I add some code to listen to image
's load
event only, it showed me that the event is trigged properly... (third snippet
).
Then I decided to write another version using $.Deferred
(fourth snippet
).
It worked...
Could you please tell me what is the problem? Thank you very much!