RxJSInAction / rxjs-in-action

Code sample repository
132 stars 59 forks source link

Listing 4.7 code doesn't match associated marble diagram #17

Open peerreynders opened 6 years ago

peerreynders commented 6 years ago

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
luijar commented 6 years ago

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!