rxjs-in-action icon indicating copy to clipboard operation
rxjs-in-action copied to clipboard

Listing 4.7 code doesn't match associated marble diagram

Open peerreynders opened this issue 7 years ago • 1 comments

https://github.com/RxJSInAction/rxjs-in-action/blob/master/examples/4/7/4_7.js

does not correspond to the marble diagram (p.99, Figure 4.8) of 4.3.1 Propagation. Due to the use of the of static operator there is only a single event containing an array of five elements - not five events as depicted in the marble diagram. For that the from static operator has to be used:

const showEmitted = x => console.log(`Emitted: ${x}`);
const showReceived = x => console.log(`Received: ${x}`);

Rx.Observable.from([1, 2, 3, 4, 5])
  .do(showEmitted)
  .delay(200)
  .subscribe(showReceived);

// Output:
// Emitted: 1
// Emitted: 2
// Emitted: 3
// Emitted: 4
// Emitted: 5
// ... 200 milliseconds later...
// Received: 1
// Received: 2
// Received: 3
// Received: 4
// Received: 5

peerreynders avatar Mar 23 '18 15:03 peerreynders

Yup. You're absolutely right. That should have been Observable.from(...). @paulpdaniels Let's add this to the errata page. Thanks @peerreynders for the catch!

luijar avatar Mar 25 '18 16:03 luijar