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.
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.
|.||One tick of elapsed time|
|( )||A grouped set of coinciding events|
|A-Z, 0-9||onNext() event|
The easiest way to convert a marble string directly to an observable is to call rxify.of, rxify.just, or rxify.from:
var rxify = ;var obs = rxify;obs = rxify;obs = rxify;console;// Output: 'A...B...'
You can also pass these strings directly in as normal arguments:
obs = rxify;console;// Output: 'A...B...C...'
obs = rxifyconsole;// Output: 'A...B...C...'
obs = rxify;console;// Output: '(A1)...(B2)'
If you'd like to see a verbose colorized step-by-step breakdown on a chained set of operations, you can call the extended
obs = rxify;obsdisplay;// Outputs:// OPERATION ARGUMENTS OUTPUT// zip ["A...B...C...","123"] (A1)...(B2)...(C3)...|// take  (A1)...(B2)|
Dealing with Time
Note: 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 // Interpreted as '...'
Note: You can also represent the argument as a sequence string:
var seqa = 'A...B.....C';var seqb = '..1...2.3..';var seqc = 'x....y....z';var obs = rxify;console;// Output: '..(A1x).(B1x)(B1y)(B2y).(B3y).(C3z)'
var i = 0;console;// Output: 'doWhile example: Aa.Aa.Aa.Aa.Aa.'
var seq = '123456789';console;// Output: 'filter example: .188.8.131.52.'
console;// 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;// 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
Supported Observable Instance Methods