ReactiveX / learnrx

A series of interactive exercises for learning Microsoft's Reactive Extensions Library for Javascript.
1.4k stars 292 forks source link

Bug - Exercise 37 does not show a movie list #177

Closed seanpoulter closed 5 years ago

seanpoulter commented 5 years ago

When you run Exercise 37, the alert box does not show the expected movie list. There are 3 problems here:

  1. Observable.prototype.forEach is now returning a Promise. This is the same problem that's causing the console error in #160. I'd suggest we change the exercise to use do to traverse events.

  2. Not all of the functions for the Observable signature have been updated from v4 to v5 so we're getting a TypeError:

    image

    These should be changed at https://github.com/ReactiveX/learnrx/blob/gh-pages/index.html#L4573-L4592

  3. With both of those changes made, there's a TypeError thrown from the "load" event handler:

    image

    We fake addEventListener with a call to setTimeout but we don't pass a fake event in at https://github.com/ReactiveX/learnrx/blob/gh-pages/index.html#L4603-L4608. This would be better off using something like:

    {
        addEventListener: function(event, handler) {
            window.setTimeout(function(){
                var fakeEvent = { preventDefault: NOOP };
                handler(fakeEvent);
            }, 200);
        },
        removeEventListener: NOOP
    },
seanpoulter commented 5 years ago
  1. After those fixes, the output still doesn't match what's expected from Exercise 35. 😓

    Expected Result

    [{
        "name": "Thrillers",
        "videos": [234324, 234322314, 23, 5, 435, 12, 3, 234, 34, 23324]
    }, {
        "name": "New Releases",
        "videos": [234324, 234322314, 23, 5, 435, 12, 3, 234, 34, 23324]
    }, {
        "name": "Instant Queue",
        "videos": [234324, 234322314, 23, 5, 435, 12, 3, 234, 34, 23324]
    }]

    Actual Result

    {
        "2": {
            "name": "Instant Queue",
            "videos": [234324, 234322314, 23, 5, 435, 12, 3, 234, 34, 23324]
        },
        "length": 3
    }


    Cause When we create copyOfMovieLists using Object.create with one argument, we create a new array with the same prototype but none of the properties or elements.

    Proposed Solution To return a new array, let's start with an empty array and add the movie list and instant queue:

      function(queue, movieListsMessage) {
    -     var copyOfMovieLists = Object.create(movieListsMessage.list);
    +     var copyOfMovieLists = [].concat(movieListsMessage.list);

Edit: Caught my own error using push vs concat().