{"id":13875,"date":"2016-07-13T12:15:36","date_gmt":"2016-07-13T09:15:36","guid":{"rendered":"https:\/\/www.webcodegeeks.com\/?p=13875"},"modified":"2016-07-12T11:59:11","modified_gmt":"2016-07-12T08:59:11","slug":"fiddling-rxjs-streams","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/","title":{"rendered":"Fiddling with RxJs Streams"},"content":{"rendered":"<p>In this post I\u2019ll touch on the emergence of JavaScript reactive streams. We\u2019ll look at a cool online interactive tool that is useful for checking behavior of stream operators. I\u2019ll finish by showing six RxJs JSFiddle examples that you can run and modify.<\/p>\n<h2>Background<\/h2>\n<p>Rich applications, such as modern SPAs, deal in state changes due to events. We\u2019re accustomed to having each interested event listener self-register a callback with an event emitter. That\u2019s the observer pattern. This pattern is dynamic and more workable than hard-coding each event emitter to invoke foreign callbacks.<\/p>\n<p>Nowadays a complex application may have a morass of cooperating event handlers that have intermittent life cycles. This is hard to reason about. It can lead to memory leaks from dangling listeners, intermittent navigation-instigated rogue behaviors, or a triangle-of-doom handler tangle in source code.<\/p>\n<p>Promises mitigate many problems by flattening callback source. They are a uniform result container. <a href=\"https:\/\/keyholesoftware.com\/2014\/07\/23\/javascript-promises-are-cool\/\" target=\"_blank\">I\u2019ve written about promises<\/a>. A settled promise eventually contains a future data result or an error value. That promise is immutable. It\u2019s one-shot: valid for only a single event.<\/p>\n<p>We often deal with successive sequences of events. Think of mouse position movement; it produces a stream of cooperating events that we may need to handle. Imagine implementing a drag-drop for example.<\/p>\n<h3>Reactive Stream<\/h3>\n<p>A reactive stream elevates the observer pattern to a uniform framework. It\u2019s been called \u201cThe observer pattern done right.\u201d It provides a pushed stream of items that we can transform, merge with other streams, or reduce to a single value. Functional programming techniques are in-play. Among them are reliance on first-class functions (passed as data), high-order functions (parameter functions; return value function), and lambdas (anonymous functions).<\/p>\n<p>Event stream processing resembles the iterator pattern familiar in data streams. Events are divas, however. They occur unpredictably. Thus, event streams use a push model. Iterators use a pull model. Three nutshell concepts are:<\/p>\n<ul>\n<li>Reactive (adjective \u2013 medieval Latin): responds to a stimulus in a particular manner.<\/li>\n<li>Stream (noun \u2013 middle English): a steady succession (as of items or events).<\/li>\n<li>Push versus pull \u2013 event streams versus data streams.<\/li>\n<\/ul>\n<p>The following diagram shows a reactive stream pattern. An <code>Observable<\/code> wraps an item that is an event source. An <code>Observable.subscribe<\/code> triggers an intermittent stream of discrete items. It is the stream\u2019s listener. An <code>Observable<\/code> can wrap almost any kind of data, including promises, or nothingness.<\/p>\n<p>A set of well-known operators can tap into its output stream. Those are higher-order functions that often take a parameter lambda, object, or a primitive. Each operator takes a value from the stream, returning a value onto the stream. Together, they resemble a monadic chain process. An operator\u2019s parameter function could internally start a new stream or combine two streams.<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive1.png\"><img decoding=\"async\" class=\"aligncenter wp-image-13881 size-large\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive1-1024x502.png\" alt=\"Reactive1\" width=\"620\" height=\"304\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive1-1024x502.png 1024w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive1-300x147.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive1-768x377.png 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive1.png 1158w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<h3>ReactiveX<\/h3>\n<p>It\u2019s difficult to roll your own reactive stream framework. There are several packages available across platforms and languages. I focused on ReactiveX. See <a href=\"http:\/\/reactivex.io\/intro.html\" target=\"_blank\">http:\/\/reactivex.io\/intro.html<\/a>. The introduction explains it nicely. It\u2019s an umbrella project that has a JavaScript binding named \u201cReactive Extensions,\u201d or RxJs.<\/p>\n<p>I used the RxJs framework in examples that follow. Refer to <a href=\"https:\/\/github.com\/Reactive-Extensions\/RxJS\/blob\/master\/readme.md\" target=\"_blank\">https:\/\/github.com\/Reactive-Extensions\/RxJS\/blob\/master\/readme.md<\/a>.<br \/>\nA side-benefit of ReactiveX technology is that it cleans up event listeners. Programmers that use traditional event listeners must be ever-mindful of disengaging unneeded listeners, or these will be memory leaks.<\/p>\n<p>The reactive mode of programming could be difficult to ease into. The next section of this article shows an interactive reference tool that help to visualize various operator functions. Afterward, I\u2019ll show six JsFiddle snippets that cover disparate use cases.<\/p>\n<h3>Marble Diagrams<\/h3>\n<p>Applying operators for transforming, filtering, and merging streams is a distinct way of reasoning about an event solution. For reference, try this API reference: <a href=\"https:\/\/github.com\/Reactive-Extensions\/RxJS\/blob\/master\/doc\/api\/core\/observable.md\" target=\"_blank\">https:\/\/github.com\/Reactive-Extensions\/RxJS\/blob\/master\/doc\/api\/core\/observable.md<\/a>.<\/p>\n<p>Some of us can learn in a visually interactive manner. Look at the interactive visualization tool at <a href=\"http:\/\/rxmarbles.com\/\" target=\"_blank\">http:\/\/rxmarbles.com\/<\/a>.<\/p>\n<p>Want to see what really happens when you operate on streams? For example, a marble diagram of the merge operator allows you to drag event marbles of two input streams to instantly see the output stream. Read on \u2026<\/p>\n<h3>Combining<\/h3>\n<p>Here\u2019s the <code>merge<\/code> combining operator. The two topmost input streams apply merge operator to produce the bottom output stream.<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive2.png\"><img decoding=\"async\" class=\"aligncenter wp-image-13882 size-large\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive2-1024x481.png\" alt=\"Reactive2\" width=\"620\" height=\"291\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive2-1024x481.png 1024w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive2-300x141.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive2-768x361.png 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive2.png 1682w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<p>Below, I\u2019ve repositioned the \u201c40\u201d and the \u201c1\u201d event marbles of the second input stream.<\/p>\n<p>See the stable ordering of the bottom output stream afterward? Apparently, Egon, of Ghostbusters, never tried crossing reactive streams.<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive3.png\"><img decoding=\"async\" class=\"aligncenter wp-image-13883 size-large\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive3-1024x488.png\" alt=\"Reactive3\" width=\"620\" height=\"295\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive3-1024x488.png 1024w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive3-300x143.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive3-768x366.png 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive3.png 1666w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<h3>Transforming<\/h3>\n<p>The well-known transformational <code>map<\/code>\u00a0operator occurs in other functional libraries that process streams, collections, or plain old arrays. Recall <code>each<\/code> or <code>forEach<\/code> from lodash and underscore.<\/p>\n<p>Additionally, there is the JS Array prototype\u2019s <code>forEach<\/code>, or the Immutable.js <code>map<\/code> function. All, including our RxJs map operator, pass a collection or stream to a caller-supplied function, creating a new output sequence.<\/p>\n<p>Here\u2019s the map marble diagram. For each member of the input, its function parameter returns ten times its numeric input parameter. In the end, it transforms the input stream, producing a new stream consisting of each input multiplied by ten. It preserves ordering.<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive4.png\"><img decoding=\"async\" class=\"aligncenter wp-image-13884 size-large\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive4-1024x362.png\" alt=\"Reactive4\" width=\"620\" height=\"219\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive4-1024x362.png 1024w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive4-300x106.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive4-768x272.png 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive4.png 1668w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<p>Below, I moved the \u201c2\u201d event marble to the extreme left to show that ordering remains.<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive5.png\"><img decoding=\"async\" class=\"aligncenter wp-image-13885 size-large\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive5-1024x364.png\" alt=\"Reactive5\" width=\"620\" height=\"220\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive5-1024x364.png 1024w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive5-300x107.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive5-768x273.png 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive5.png 1666w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<h3>Filtering<\/h3>\n<p>We\u2019ll see a <code>takeUntil<\/code> filtering operator in a later drag-drop example. Look at that operator\u2019s marble diagram. The second input stream conditionally filters the first stream\u2019s members into the output stream. The second JS stream\u2019s earliest false \u201c0\u201d item halts output. Note the vertical bar on the bottom output that shows the end of the output stream.<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive6.png\"><img decoding=\"async\" class=\"aligncenter wp-image-13886 size-large\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive6-1024x480.png\" alt=\"Reactive6\" width=\"620\" height=\"291\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive6-1024x480.png 1024w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive6-300x140.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive6-768x360.png 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive6.png 1670w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<p>Below, I\u2019ve moved the rightmost middle stream \u201c0\u201d item leftward to just after the \u201c2\u201d item of the upper stream. The <code>takeUntil<\/code> stops replicating the upper stream there, now producing a result stream containing only \u201c1\u201d and \u201c2\u201d. Again RxJs preserved the ordering.<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive7.png\"><img decoding=\"async\" class=\"aligncenter wp-image-13887 size-large\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive7-1024x478.png\" alt=\"Reactive7\" width=\"620\" height=\"289\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive7-1024x478.png 1024w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive7-300x140.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive7-768x359.png 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive7.png 1674w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<h3>JSFiddle Examples<\/h3>\n<p>Each example depends only upon the RxJs library and JQuery. I dropped back to ES5 syntax in the online JSFiddle code because Safari doesn\u2019t support arrow functions. The following examples do use ES6 syntax. See <a href=\"https:\/\/babeljs.io\/docs\/learn-es2015\/\" target=\"_blank\">https:\/\/babeljs.io\/docs\/learn-es2015\/<\/a> for succinct examples of ES6 and ES2015.<\/p>\n<h2>Example 1: A Stream of Nothing<\/h2>\n<p>Recall that an <code>Observable<\/code> represents a push-based collection. In RxJS, an Observable can front any number of legal JavaScript entity or entities. Let\u2019s lean on the boundary. How about an empty Observable?<\/p>\n<p>Yes, but what use is a stream of nothing? Well, it\u2019s an edge case. Consider a dynamic application that might need to handle a source of any number of indeterminate dynamic items, including an undefined JS value. We can handle that.<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive8.png\"><img decoding=\"async\" class=\"aligncenter wp-image-13888\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive8.png\" alt=\"Reactive8\" width=\"600\" height=\"180\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive8.png 826w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive8-300x90.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive8-768x231.png 768w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive9.png\"><img decoding=\"async\" class=\"aligncenter wp-image-13889\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive9.png\" alt=\"Reactive9\" width=\"600\" height=\"120\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive9.png 838w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive9-300x60.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive9-768x154.png 768w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>Refer to JSFiddle <a href=\"https:\/\/jsfiddle.net\/mauget\/3u4po86u\/\" target=\"_blank\">https:\/\/jsfiddle.net\/mauget\/3u4po86u\/<\/a>. It produces an <code>Observable<\/code> by mumbling an <code>Rx.Observable.empty()<\/code> incantation. Nothing happens until the Observable suffers a <code>subscribe<\/code> function call. An RxJs subscribe can take three optional functional parameters:<\/p>\n<ul>\n<li><code>onNext<\/code><\/li>\n<li><code>onError<\/code><\/li>\n<li><code>onCompletion<\/code><\/li>\n<\/ul>\n<p>The <code>onError<\/code> and <code>onCompletion<\/code> calls are mutually exclusive. The framework invokes one or the other, not both. For effect I used a <code>window.setTimeout<\/code> to delay invoking the subscribe until three seconds pass. When the timer pops, I call subscribe. The stream immediately awakens to push the \u201cempty\u201d item. The <code>onCompletion<\/code> logs a message and updates the DOM with the message.<\/p>\n<pre class=\"brush:perl\">const\r\n  delay = 3, \/\/ seconds\r\n  source = Rx.Observable.empty(), \/\/ Dormant until subscription occurs\r\n  msg1 = `Will subscribe to empty source in ${delay} seconds ...\r\n`; \r\n\r\n$('body').append(msg1);  \/\/ HTML output\r\nconsole.log(msg1);       \/\/ deb log output  -\r\n\r\nwindow.setTimeout( () =&gt; {\r\n  const msg2 = `Subscribing ... here comes the data ...`;\r\n  $('body').append(`\r\n${msg2}`);\r\n  console.log(msg2);\r\n\r\n  \/\/ Kick the stream\r\n  source.subscribe(\r\n    v =&gt; console.log(`onNext: ${v}`),  \/\/ arg1 fn\r\n    v =&gt; console.log(`onError: ${v}`), \/\/ arg2 fn\r\n    v =&gt; {                           \/\/ arg3 fn\r\n      const msg3 = `yes ... received the expected \"${v}\" from the stream.`;\r\n      $('body').append(`\r\n\t\t${msg3}`);\r\n      console.log(msg3);\r\n    }\r\n  );\r\n}, delay * 1000 );<\/pre>\n<h2>Example 2: Time Interval<\/h2>\n<p>Example 1 had a standard <code>window.setTimer<\/code> that provided a timed interval as a demo prop.<\/p>\n<p>You object: \u201cIsn\u2019t a timer expiration an event? I thought RxJs is about observing events!\u201d Yup. In that hello-world kind of snippet, I didn\u2019t want to confuse a trivial stream example by involving a second stream.<\/p>\n<p>Now you\u2019re ready, Grasshopper! Let\u2019s observe timer expirations via RxJs. An <code>Observable<\/code> stream of timer expirations will generate a dynamically increasing trip counter of values. Refer to the JSFiddle at <a href=\"https:\/\/jsfiddle.net\/mauget\/t03fcr8y\/\" target=\"_blank\">https:\/\/jsfiddle.net\/mauget\/t03fcr8y\/<\/a>. It generated the before and after panels here.<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive91.png\"><img decoding=\"async\" class=\"aligncenter wp-image-13890\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive91.png\" alt=\"Reactive91\" width=\"550\" height=\"177\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive91.png 672w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive91-300x96.png 300w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive92.png\"><img decoding=\"async\" class=\"aligncenter wp-image-13891\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive92.png\" alt=\"Reactive92\" width=\"550\" height=\"170\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive92.png 684w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive92-300x93.png 300w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><\/p>\n<p>Look at the code below. Notice the RxJs <code>interval<\/code>, <code>skip<\/code>, and <code>take<\/code> operators that sequentially process the stream input items into an output stream? Those govern the pace, content, and extent of the product stream.<\/p>\n<p>The interval operator is the heart of the code. See <a href=\"https:\/\/github.com\/Reactive-Extensions\/RxJS\/blob\/master\/doc\/api\/core\/operators\/interval.md\" target=\"_blank\">https:\/\/github.com\/Reactive-Extensions\/RxJS\/blob\/master\/doc\/api\/core\/operators\/interval.md<\/a>. This is a reworked example from RxJs samples. At each delayed invocation the interval call injects a numeric value from a monotonically-increasing zero-origin set.<\/p>\n<p>The <code>skip(0)<\/code> operator omits the zeroth item. The <code>take(10)<\/code> limits processing to ten output members.<\/p>\n<p>The <code>subscribe<\/code> call starts the stream. Its <code>onNext<\/code> functional parameter calculates a current odometer value from each emitted stream item. The <code>onError<\/code> and <code>onCompletion<\/code> functional parameters log their respective calls.<\/p>\n<pre class=\"brush:perl\">\/\/ distance = rate * time\r\nconst R = 60; \/\/ mph \r\nlet t = 0; \/\/ We'll step up at intervals\r\n\r\nconst source = Rx.Observable\r\n  .interval(500) \/\/ 1\/2 second interval\r\n  .skip(1) \/\/ Skip zeroth\r\n  .take(10); \/\/ Take next 10\r\n\r\n\/\/ Kick off ...\r\nconst subscription = source.subscribe(\r\n  t =&gt; {\r\n    console.log('hours: ' + t);\r\n    $('#mph').html(R);\r\n    $('#hours').html(t);\r\n    $('#miles').html(R * t); \/\/ Do the math, display it\r\n  },\r\n  err =&gt; console.log('Error: ' + err),\r\n  () =&gt; console.log('Completed'));<\/pre>\n<h2>Example 3: Interactive Character \/ Word Counter<\/h2>\n<p>Let\u2019s maintain a dynamic count of words and non-whitespace characters. They\u2019re entered or pasted live into an HTML textarea element. Backspace or delete keys decrement the counts. I count whatever is held in the textarea at each event instant.<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive93.png\"><img decoding=\"async\" class=\"aligncenter wp-image-13892\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive93.png\" alt=\"Reactive93\" width=\"600\" height=\"328\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive93.png 992w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive93-300x164.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive93-768x420.png 768w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>Refer to <a href=\"https:\/\/jsfiddle.net\/mauget\/o6rprdhx\/\" target=\"_blank\">https:\/\/jsfiddle.net\/mauget\/o6rprdhx\/<\/a>. It\u2019s another reworked RxJs sample. It defines an <code>Observable<\/code> of a DOM textarea keyup event. The <code>Observable<\/code> fronts a push-based collection consisting of a single object that holds the character count and word count of the textarea. The snippet generates the contents from a jQuery <code>map<\/code> function chained to an event selector. The map callback uses regular expressions to count current non-whitespace characters and words held within the textarea.<\/p>\n<p>Nothing happens until the <code>subscribe<\/code> call on the Observable. The <code>subscribe<\/code>\u2019s <code>onNext<\/code> function parameter populates the result, much like a traditional event callback. I omitted <code>onError<\/code> and <code>onCompletion<\/code> callback functions. A pushed Observable-to-subscribe event pulse occurs at each keyup. The <code>onNext<\/code> carries out an instant update of the two counts in the UI and console log.<\/p>\n<pre class=\"brush:perl\">\/\/ #A. DOM elements-of-interest from DOM query selectors\r\nconst\r\n  $txtInput = $('#txtInput'),\r\n  $charCount = $('#charCount'),\r\n  $wordCount = $('#wordCount');\r\n\r\n\/\/ #B. Observable of keyup triggered at textInput -- it's a monad\r\nRx.Observable.fromEvent($txtInput.get(0), 'keyup')\r\n  .map(e =&gt; {\r\n    return {\r\n      cc: (e.target.value.match(\/[^\\s]\/g) || []).length,\r\n      wc: (e.target.value.match(\/\\b\\S+\\b\/g) || []).length\r\n    }\r\n  })\r\n  \/\/ #C. Kick off the stream\r\n  .subscribe(v =&gt; {\r\n    console.log(v);\r\n    $charCount.html(` Chars: ${v.cc}`);\r\n    $wordCount.html(` Words: ${v.wc}`);\r\n  });<\/pre>\n<h2>Example 4: Drag and Drop<\/h2>\n<p>Here is a simple drag-drop example. It uses cooperating Observables on the events: mousedown, mousemove, and mouseup. These collectively implement dragging and dropping a DOM item anywhere within a panel.<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive94.png\"><img decoding=\"async\" class=\"aligncenter wp-image-13893 size-large\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive94-1024x234.png\" alt=\"Reactive94\" width=\"620\" height=\"142\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive94-1024x234.png 1024w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive94-300x69.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive94-768x176.png 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive94.png 1118w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive95.png\"><img decoding=\"async\" class=\"aligncenter wp-image-13894 size-large\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive95-1024x249.png\" alt=\"Reactive95\" width=\"620\" height=\"151\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive95-1024x249.png 1024w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive95-300x73.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive95-768x187.png 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive95.png 1120w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<p>Refer to the JsFiddle at <a href=\"https:\/\/jsfiddle.net\/mauget\/9bhp0qu8\/\" target=\"_blank\">https:\/\/jsfiddle.net\/mauget\/9bhp0qu8\/<\/a>. Try dragging the fruit. This snippet, too, grew out of an RxJs example. It creates three kinds of mouse action observables. The code enables a user to reposition a draggable fruit image on a panel.<\/p>\n<p>The subscribe to the mousedown Observable fruit starts the action. The event item on the fruit chains to a <code>flatMap<\/code> operator chained to a <code>takeUntil<\/code> mouseup operator. A <code>flatMap<\/code> is a common function encountered in functional programming. It\u2019s a <code>map<\/code> function that flattens its input sequences into a single output sequence.<\/p>\n<pre class=\"brush:perl\">(function(dragable) {\r\n\r\n  \/\/ Observe three major kinds of mouse events:\r\n  \/\/ mousedown, mouseup on the dragable; mousemove over the document.\r\n  const\r\n    mousedown = Rx.Observable.fromEvent(dragable, 'mousedown'),\r\n    mousemove = Rx.Observable.fromEvent(document, 'mousemove'),\r\n    mouseup   = Rx.Observable.fromEvent(dragable, 'mouseup');\r\n\r\n  \/\/ A. Detect mouse down; \r\n  \/\/ B. While down, listen for mouse move and mouse up;\r\n  \/\/ C. When mouse up: stop listening for moves and mouse up.\r\n  const mousedrag = mousedown.flatMap( md =&gt; {\r\n\r\n    \/\/ Capture mouse down offset position\r\n    const\r\n      startX = md.offsetX,\r\n      startY = md.offsetY;\r\n\r\n    \/\/ B1. Track pos differentials using mousemove, until mouseup\r\n    return mousemove.map( mm =&gt; {\r\n      mm.preventDefault();\r\n\r\n      return {\r\n        left: mm.clientX - startX,\r\n        top: mm.clientY - startY\r\n      };\r\n      \/\/ C. stop the drag when mousup\r\n    }).takeUntil(mouseup);\r\n  })\r\n\r\n  \/\/ Subscribe to mousemove's mousedrag stream:\r\n  \/\/ B2. Update draggable's position from mousedrag stream of events\r\n  mousedrag.subscribe( pos =&gt; {\r\n    dragable.style.top = pos.top + 'px';\r\n    dragable.style.left = pos.left + 'px';\r\n  });\r\n\r\n})($('#dragable').get(0));<\/pre>\n<h2>Example 5: AJAX Promise \u2013 A Set of Quantum-Random Numbers<\/h2>\n<p>Let\u2019s display a set of profoundly random numbers requested from a REST service.<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive96.png\"><img decoding=\"async\" class=\"aligncenter wp-image-13895 size-large\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive96-1024x626.png\" alt=\"Reactive96\" width=\"620\" height=\"379\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive96-1024x626.png 1024w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive96-300x183.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive96-768x469.png 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive96.png 1326w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<p>Refer to JSFiddle <a href=\"https:\/\/jsfiddle.net\/mauget\/b0jfmge6\/\" target=\"_blank\">https:\/\/jsfiddle.net\/mauget\/b0jfmge6\/<\/a>. In this example, we access the random number REST service via AJAX. We can make an <code>Observable<\/code> for almost anything. We\u2019ll observe a promise. An AJAX call can return a promise to provide asynchronous behavior that we need to drive a UI from a latent network response. The stream will push the promise.<\/p>\n<p>To review, a promise is either pending or settled. If it settles to a <code>success<\/code> state, it forever returns the data it contains from that success. Thus you can call <code>then<\/code> on that promise whenever you desire, as often as you desire, but it will always return its settled success or reject value for its lifespan.<\/p>\n<p>Our example observes a button click. The click <code>Observable<\/code>, <code>onNext<\/code>, displays a <code>working<\/code> banner. A chained <code>flatMap<\/code> operator calls <code>getNumbers<\/code> to create a second <code>Observable<\/code> from a promise. That promise is an immediate result of an AJAX call to the REST service. This is easier to understand by looking at the snippet.<\/p>\n<p>The <code>flatMap<\/code> operator gates the settled <code>then<\/code> object payload of the promise <code>Observable<\/code> onto the button click stream as a flat sequence of numbers. A subscribe on the button click stream displays the random numbers.<\/p>\n<p>I kick off activity by triggering a refresh button click at the bottom of the code. Notice what happens if you click the button repeatedly? You see the identical random number sequence repainted!<\/p>\n<p>I claimed the sequence is random, so why does it repeat? Answer: because the promise stream already resolved that settled one-shot AJAX promise. There is no second network invocation.<\/p>\n<pre class=\"brush:perl\">const $button = $('#button'),\r\n  $result = $('#result');\r\n\r\n\/\/ AJAX fn: returns observable promise\r\nconst getNumbers = count =&gt; {\r\n  return Rx.Observable.fromPromise(\r\n    \/\/ Get promise of: {\"type\":\"uint8\",\"length\":1,\"data\":[99],\"success\":true}\r\n    $.ajax({\r\n      url: `https:\/\/qrng.anu.edu.au\/API\/jsonI.php?length=${count}&amp;type=uint8`\r\n    })\r\n    .promise());\r\n};\r\n\r\n\/\/ Observe button click, subscribe to result\r\nRx.Observable.fromEvent($button.get(0), 'click')\r\n  .map(e =&gt; {\r\n    $result.html('&lt;span class=\"working\"&gt;(working)&lt;\/span&gt;');\r\n    return e.target.value;\r\n  }).flatMap(getNumbers(300))\r\n  .subscribe(d =&gt; {\r\n    let sep = '';\r\n    console.log(d);\r\n    if (d.success) {\r\n      $result.empty();\r\n      d.data.forEach(v =&gt; {\r\n        $result.append(sep + v);\r\n        sep = ', ';\r\n      });\r\n    }\r\n  });\r\n\r\n$button.trigger('click');<\/pre>\n<h2>Sidebar<\/h2>\n<p>As a physics major diverted to computer programming, I\u2019m compelled to speak about our data.<\/p>\n<p>The numbers originate from a vacuum chamber in Canberra, Australia. A vacuum that emits random numbers! The count of particles and photons is zero in a perfect dark classical vacuum. At the quantum level, however, a vacuum is weird. A lab at the Australian National University measures field variations from continually materializing and dematerializing virtual particle pairs. See <a href=\"https:\/\/en.wikipedia.org\/wiki\/Virtual_particle\" target=\"_blank\">https:\/\/en.wikipedia.org\/wiki\/Virtual_particle<\/a>.<\/p>\n<p>A REST service streams those values. Statistical tests show that the sequence is profoundly random.<\/p>\n<h2>Example 6: AJAX Promise \u2013 A Quilt of Quantum-Random Colors<\/h2>\n<p>My wife is a quilter. I couldn\u2019t resist converting example 5 output into a random patch quilt.<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive97.png\"><img decoding=\"async\" class=\"aligncenter wp-image-13896 size-large\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive97-1024x517.png\" alt=\"Reactive97\" width=\"620\" height=\"313\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive97-1024x517.png 1024w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive97-300x151.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive97-768x388.png 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/Reactive97.png 1232w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<p>Refer to JSFiddle <a href=\"https:\/\/jsfiddle.net\/mauget\/9c2ecLqs\/\" target=\"_blank\">https:\/\/jsfiddle.net\/mauget\/9c2ecLqs\/<\/a>. The code is largely that of example 5, aside from presentation logic in the <code>subscribe<\/code> call. The subscribe callback forces each sequence item into a number of the interval 0 \u2026 255. It combines each group of three into one CSS RGB value. Finally, it emits each RGB value into a grid. Again, notice that the refresh button causes an identical quilt to render after the first rendering. That settled promise remains immutable and happy.<\/p>\n<pre class=\"brush:perl\">const valCount = 1020;\r\nconst $button = $('#button'),\r\n      $result = $('#result');\r\n      \r\n\/\/ AJAX fn: returns observable promise\r\nconst getNumbers = count =&gt; {\r\n  return Rx.Observable.fromPromise(\r\n    \/\/ Get promise of: {\"type\":\"uint8\",\"length\":1,\"data\":[99],\"success\":true}\r\n    $.ajax({\r\n      url: `https:\/\/qrng.anu.edu.au\/API\/jsonI.php?length=${count}&amp;type=uint8`})\r\n      \t.promise());\r\n};\r\n\r\n\/\/ Listen for button clicks, do service request, subscribe to result\r\nRx.Observable.fromEvent($button.get(0), 'click')\r\n  .map(e =&gt; {\r\n  $result.html('&lt;span class=\"working\"&gt;(working)&lt;\/span&gt;');\r\n  return e.target.value;\r\n})\r\n  .flatMap( getNumbers( valCount ) )\r\n  .subscribe(data =&gt; {\r\n  \tconsole.log(data);\r\n  \tif (data.success) {\r\n   \t $result.empty();\r\n    \tlet cols = 0\r\n    \tconst c = []; \/\/ rgb value\r\n\r\n   \t data.data.forEach( v =&gt; {\r\n      c.push( v % 256 );\r\n      if (c.length &gt; 2 ) {\r\n        const rgb = `rgb(${c.pop()},${c.pop()},${c.pop()})`;\r\n        $result.append(\r\n`&lt;span style=\"background-color:${rgb}\"&gt;\u00a0\u00a0\u00a0\u00a0&lt;\/span&gt;`);\r\n\r\n        if ( ++cols &gt; 33 ) {\r\n          $result.append(`\r\n`);\r\n          cols = 0;\r\n        }\r\n      }\r\n    });\r\n  }\r\n});\r\n\r\n$button.trigger('click');<\/pre>\n<h2>Wrap-Up<\/h2>\n<p>Reactive streams are a unified way of dealing with asynchronous events. They\u2019re a higher-level implementation of the observer pattern. They rely on functional programming. An <code>Observable<\/code> pushes events onto a stream. Operators modify it. A subscribe operator starts, handles, and ends stream processing.<\/p>\n<p>This paradigm may require a shift of your thinking for programming in an asynchronous environment. Marble diagrams help to understand many functional operators used in ReactiveX.<\/p>\n<p>We saw six operational RxJs snippets that support varying use cases. You could run and modify them on JSFiddle for familiarization. Reactive streaming libraries exist across platforms and operating systems. ReactiveX is fairly unified across the board, so concepts from this article could apply beyond JavaScript.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"https:\/\/keyholesoftware.com\/2016\/07\/11\/fiddling-with-rxjs-streams\/\">Fiddling with RxJs Streams<\/a> from our <a href=\"http:\/\/www.webcodegeeks.com\/join-us\/wcg\/\">WCG partner<\/a>\u00a0Lou Mauget at the <a href=\"http:\/\/keyholesoftware.com\/\">Keyhole Software<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this post I\u2019ll touch on the emergence of JavaScript reactive streams. We\u2019ll look at a cool online interactive tool that is useful for checking behavior of stream operators. I\u2019ll finish by showing six RxJs JSFiddle examples that you can run and modify. Background Rich applications, such as modern SPAs, deal in state changes due &hellip;<\/p>\n","protected":false},"author":138,"featured_media":920,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[334],"class_list":["post-13875","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-rxjs"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Fiddling with RxJs Streams - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"In this post I\u2019ll touch on the emergence of JavaScript reactive streams. We\u2019ll look at a cool online interactive tool that is useful for checking behavior\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Fiddling with RxJs Streams - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"In this post I\u2019ll touch on the emergence of JavaScript reactive streams. We\u2019ll look at a cool online interactive tool that is useful for checking behavior\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-13T09:15:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Lou Mauget\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Lou Mauget\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"15 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/\"},\"author\":{\"name\":\"Lou Mauget\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/fa86f2720cff287f9febcbac27f18776\"},\"headline\":\"Fiddling with RxJs Streams\",\"datePublished\":\"2016-07-13T09:15:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/\"},\"wordCount\":2316,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg\",\"keywords\":[\"RxJs\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/\",\"name\":\"Fiddling with RxJs Streams - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg\",\"datePublished\":\"2016-07-13T09:15:36+00:00\",\"description\":\"In this post I\u2019ll touch on the emergence of JavaScript reactive streams. We\u2019ll look at a cool online interactive tool that is useful for checking behavior\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Fiddling with RxJs Streams\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/fa86f2720cff287f9febcbac27f18776\",\"name\":\"Lou Mauget\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ff02d57c0b5c64f1fa36854ec195f49741f59179efb2aa8d744cad816be9792f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ff02d57c0b5c64f1fa36854ec195f49741f59179efb2aa8d744cad816be9792f?s=96&d=mm&r=g\",\"caption\":\"Lou Mauget\"},\"description\":\"Known as Ed Mauget in civilian life. Lou is a name imposed by IBM in 1966. Newly infatuated with Microservices Architecture. Last spring he coded MockOla, a wire-framing tool for Keyhole Software. Have coded in Java since it was conceived. Also worked with C\/C++. Current interests include microservices, Docker, Node JS, NoSQL databases, functional programming, single-page web applications \u2026 any new software languages\/frameworks.\",\"sameAs\":[\"http:\/\/www.keyholesoftware.com\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/lou-mauget\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Fiddling with RxJs Streams - Web Code Geeks - 2026","description":"In this post I\u2019ll touch on the emergence of JavaScript reactive streams. We\u2019ll look at a cool online interactive tool that is useful for checking behavior","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/","og_locale":"en_US","og_type":"article","og_title":"Fiddling with RxJs Streams - Web Code Geeks - 2026","og_description":"In this post I\u2019ll touch on the emergence of JavaScript reactive streams. We\u2019ll look at a cool online interactive tool that is useful for checking behavior","og_url":"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2016-07-13T09:15:36+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","type":"image\/jpeg"}],"author":"Lou Mauget","twitter_card":"summary_large_image","twitter_creator":"@webcodegeeks","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Lou Mauget","Est. reading time":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/"},"author":{"name":"Lou Mauget","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/fa86f2720cff287f9febcbac27f18776"},"headline":"Fiddling with RxJs Streams","datePublished":"2016-07-13T09:15:36+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/"},"wordCount":2316,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","keywords":["RxJs"],"articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/","url":"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/","name":"Fiddling with RxJs Streams - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","datePublished":"2016-07-13T09:15:36+00:00","description":"In this post I\u2019ll touch on the emergence of JavaScript reactive streams. We\u2019ll look at a cool online interactive tool that is useful for checking behavior","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/javascript\/fiddling-rxjs-streams\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/"},{"@type":"ListItem","position":3,"name":"Fiddling with RxJs Streams"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/fa86f2720cff287f9febcbac27f18776","name":"Lou Mauget","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ff02d57c0b5c64f1fa36854ec195f49741f59179efb2aa8d744cad816be9792f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ff02d57c0b5c64f1fa36854ec195f49741f59179efb2aa8d744cad816be9792f?s=96&d=mm&r=g","caption":"Lou Mauget"},"description":"Known as Ed Mauget in civilian life. Lou is a name imposed by IBM in 1966. Newly infatuated with Microservices Architecture. Last spring he coded MockOla, a wire-framing tool for Keyhole Software. Have coded in Java since it was conceived. Also worked with C\/C++. Current interests include microservices, Docker, Node JS, NoSQL databases, functional programming, single-page web applications \u2026 any new software languages\/frameworks.","sameAs":["http:\/\/www.keyholesoftware.com"],"url":"https:\/\/www.webcodegeeks.com\/author\/lou-mauget\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/13875","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/138"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=13875"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/13875\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/920"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=13875"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=13875"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=13875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}