Inspect the Behavior of Operators with RxJS do

InstructorAndré Staltz

Share this video with your friends

Send Tweet

inspect the behavior of other operators We just saw map which is a transformation operator. There are a couple of categories of operators, such as filtering, combination, flattening, etc. One of these categories is the utility operators. The most important utility operator is do, useful for debugging.

🚨 Since we are importing interval from RxJS, we don't need to preface our Observables with Rx.Observable. do is deprecated, use tap instead. You can no longer .{operator}, you need to .pipe({operator}) instead.

Kevin Pinny
~ 7 years ago

Hello Andre,

I love the series you put up here, every lesson I learn about RxJS makes me fall in love more and more with Reactive Programming. I have a question concerning the do() operator. I read that all unpure behavior like logging, changing button states, writing to local storage should be wrapped in the do() operator. Is this the general practice or are there better alternatives for this?

Kind regards, Kevin

André Staltzinstructor
~ 7 years ago

Hi Kevin. Glad to hear you are learning! I would recommend putting impure code as such in subscribe(), not do(). There are a few cases where you could use do() for impure code, but mostly they should go to subscribe(). There is an upcoming course I made (already fully recorded) which will soon be put on Egghead that teaches exactly about do() vs subscribe(). Stay tuned.