An RxJS library wrapper that lets you execute Rx operators directly using marble-diagram ASCII string arguments.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
demos
es5
es6
test
.babelrc
.eslintrc
.gitignore
README.md
gulpfile.js
package.json

README.md

rxify

An RxJS library wrapper that lets you execute Rx operators directly using marble-diagram ASCII string arguments.

rxify was mainly created as an educational tool to guide those ramping up on Reactive Extensions for the first time by presenting an alternative way to visualize and experiment on its asynchronous features. However, some folks may find it useful for other purposes such as general problem-solving or simplifying unit tests.

Installation
npm install rxify
Marble Notation / Terminology

Each string argument is basically an observable sequence expressed in ASCII marble diagram notation. For example, the string 'A...B' represents a stream of two events separated by some passage of time. In rxify the actual unit of time is not important, so it may be easier to just imagine each '.' as one tick of time. Also, to simplify things further, the end of a string is automatically interpreted as an onCompleted action. Technically you can represent that with '|' but it's purely optional.

Sequence Character Meaning
. One tick of elapsed time
| onCompleted() event
! onError() event
( ) A grouped set of coinciding events
A-Z, 0-9 onNext() event
Basic Examples

The easiest way to convert a marble string directly to an observable is to call rxify.of, rxify.just, or rxify.from:

var rxify = require('rxify');
var obs = rxify.of('A...B...');
obs = rxify.just('A...B...');
obs = rxify.from('A...B...');
console.log(obs.toString());
// Output: 'A...B...'

You can also pass these strings directly in as normal arguments:

obs = rxify.concat('A...','B...','C...');
console.log(obs.toString());
// Output: 'A...B...C...'
Chaining Operators
obs = rxify.of('A...B...').concat('C...')
console.log(obs.toString());
// Output: 'A...B...C...'
obs = rxify.zip('A...B...C...','123').take(2);
console.log(obs.toString());
// Output: '(A1)...(B2)'
Visualizing Output

If you'd like to see a verbose colorized step-by-step breakdown on a chained set of operations, you can call the extended display() method.

obs = rxify.zip('A...B...C...','123').take(2);
obs.display();
// Outputs:
// OPERATION ARGUMENTS              OUTPUT
// zip       ["A...B...C...","123"] (A1)...(B2)...(C3)...|
// take      [2]                    (A1)...(B2)|

Dealing with Time

When calling a RxJS operator that normally expects a time-based argument in milliseconds, with rxify you should instead pass in the desired number of ticks. For example:

rxify.delay(3) // Interpreted as '...'

You can also represent the argument as a sequence string:

rxify.delay('...')
More Examples
var seqa = 'A...B.....C';
var seqb = '..1...2.3..';
var seqc = 'x....y....z';
var obs = rxify.combineLatest(seqa, seqb, seqc );
console.log(obs.toString());
// Output: '..(A1x).(B1x)(B1y)(B2y).(B3y).(C3z)'
var i = 0;
console.log('doWhile example: ' + rxify.from('Aa.').
            doWhile(function() {
                return ++i <= 4;
            })
);
// Output: 'doWhile example: Aa.Aa.Aa.Aa.Aa.'
var seq = '123456789';
console.log('filter example: ' + rxify.from(seq).
    filter(function(elem) {
        return elem % 2 == 0;
    })
);
// Output: 'filter example: .2.4.6.8.'
console.log('bufferWithTime example: ' + rxify.interval(1).
    bufferWithTime(5,1).
    take(3)
);
// Output: 'bufferWithTime: ....(0,1,2,3,4)(0,1,2,3,4,5)(2,3,4,5,6)'
var input = 'AA..BBB..CCCC...DDDD...EEEEEE..FFFFF..GGGGG';
console.log('debounce example: ' + rxify.of(input).debounce(1).toString());
// Output: '..A....B.....C......D........E......F.....G'

If you'd like more examples on how to use rxify, please refer to these unit tests

Supported Observable Methods

  • amb
  • catch
  • combineLatest
  • concat
  • empty
  • for
  • forkJoin
  • from
  • generate
  • if
  • interval
  • just
  • merge
  • mergeDelayError
  • of
  • onErrorResumeNext
  • pairs
  • range
  • repeat
  • return
  • start
  • timer
  • while
  • zip

Supported Observable Instance Methods

  • average
  • bufferWithCount
  • bufferWithTime
  • catch
  • combineLatest
  • concat
  • count
  • debounce
  • defaultIfEmpty
  • delay
  • distinct
  • distinctUntilChanged
  • do
  • doOnCompleted
  • doOnError
  • doOnNext
  • doWhile
  • elementAt
  • every
  • filter
  • finally
  • find
  • findIndex
  • first
  • flatMap
  • flatMapLatest
  • forEach
  • forkJoin
  • ignoreElements
  • isEmpty
  • last
  • let
  • map
  • max
  • maxBy
  • merge
  • min
  • minBy
  • onErrorResumeNext
  • pairwise
  • pluck
  • reduce
  • retry
  • sample
  • scan
  • select
  • selectMany
  • sequenceEqual
  • skip
  • skipLast
  • skipLastWithTime
  • skipUntil
  • skipUntilWithTime
  • skipWhile
  • some
  • startWith
  • subscribe
  • subscribeOnCompleted
  • subscribeOnError
  • subscribeOnNext
  • sum
  • take
  • takeLast
  • takeLastBuffer
  • takeLastBufferWithTime
  • takeLastWithTime
  • takeUntil
  • takeUntilWithTime
  • takeWhile
  • tap
  • tapOnCompleted
  • tapOnError
  • tapOnNext
  • throttle
  • timeout
  • timeInterval
  • timestamp
  • toArray
  • where
  • zip