Nodejs - Quick Tips #7

Identify Streams Better when Logging Two or More Streams at a Time

Rxjs provides a means of performing a ‘side effect’ without modifying the observable through the observable chain. The ‘do’ command is good candidate for use when there is a need to log out information when specific operations are performed.

Log Action of an Observable
1
2
3
4
5
6
7
8
9
10
11
//Provide an indication of which interval has action performed
const interval1 = Rx.Observable.interval(1000);
const example1 = interval1.do(val => console.log(`Early interval, second(s) elapsed! : ${val}`));

const interval = Rx.Observable.interval(2000);
const example2 = interval.do(val => console.log(`Later interval, second(s) elapsed! : ${val}\n`));

Observable.merge(
example1,
example2
).subscribe((x) => {});

No ‘default’ Call Needed when ‘requiring’ transpiled module from Babel

The require call in a ES5 transpiled module from ES6 requires you to call the ‘default’ key of the return function value before the actually functionality can be accessed:

More Boilerplate for 'Requiring' a Module
1
2
3
4
5
6
var fantasticModule = require('my-fantastic-module-name');
fantasticModule.default();

//Have to do the above instead of:
//var fantasticModule = require('my-fantastic-module-name');
//fantasticModule();

To solve this problem use the ‘babel-plugin-add-module-exports’ module from here.

After installing that module, require calls from an ES5 environment will no longer need to make the ‘default’ key access before calling.