Skip to content

Instantly share code, notes, and snippets.

@Atibaashraf
Created October 11, 2017 11:21
Show Gist options
  • Save Atibaashraf/77e57721c2c2e92034686ac1a08d107b to your computer and use it in GitHub Desktop.
Save Atibaashraf/77e57721c2c2e92034686ac1a08d107b to your computer and use it in GitHub Desktop.
signature: do(nextOrObserver: function, error: function, complete: function): Observable - Transparently perform actions or side-effects, such as logging.
const source = Rx.Observable.of(1,2,3,4,5);
//transparently log values from source with 'do'
const example = source
.do(val => console.log(`BEFORE MAP: ${val}`))
.map(val => val + 10)
.do(val => console.log(`AFTER MAP: ${val}`));
//'do' does not transform values
//output: 11...12...13...14...15
const subscribe = example.subscribe(val => console.log(val));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment