Skip to main content


Showing posts from February, 2016

Quick Setup Using JSPM

Cross post from my employer's development blog:
Want to use JSPM rather than Bower for running the example? Follow these steps. This is basically a duplicate of the [Getting Started tutorial][tutorial] on the [ website][website] but using a really simple JSPM setup. This is a very crude guide where I list everything I had to do to get things running.

Create an empty project folder npm install Copy server code verbatim from the Getting Started guide jspm install Hit enter for all the prompts from JSPM

We’re going to modify the client side code a little bit. We have native support for ES6 compiling with JSPM/Babel so we can import the Deepstream client directly:

import deepstream from ''; let ds = deepstream( 'localhost:6020' ).login();

let record = ds.record.getRecord( 'someUser' );

let input = document.querySelector( 'inp…

Multiple Instruction Arrow Functions in ES6

Cross post from my employer's development blog:
Recently, I had a bit of JavaScript code that was a small series of map and reduce functions. To keep things nice and tight, I of course wanted to use single line arrow functions as much as possible. Implicit returns, no brackets, no ‘function’ syntax. I had one reduce() call though where my logic was this:
arr.reduce((list2, b) => {          if (list2.indexOf(b) === -1){            list2.push(b);          }          return list2;        }, []);
High level: only add item b from array arr to a new array if it doesn’t already exist in the new array. Simple duplicate removal for the original array. This works, and is probably the easiest to understand, but doesn’t make for the best grouping along with other calls on the same array. How could I modify this a bit so that I could use a bracketless arrow function with an implicit return?
arr.reduce((list2, b) =>          ((…

Debugging MapReduce in Javascript

Cross post from my employer's development blog:
With single line arrow functions in ES6, it’s getting easier and cleaner to use JS’s native and Array.prototype.reduce() functions for molding our data. I recently decided to go the MapReduce route for a project to filter some data upfront. Inevitably, I ran into some issues with my logic and wasn’t getting what I expected. Thing is, there doesn’t seem to be a simple way to add debugging to a chain of map() and reduce() calls, particularly if you’re using single line arrow functions.
     let behaviors = track.metrics        .reduce((list1, m) => list1.concat(m.behaviors), [])        .reduce((list2, b) =>          ((list2.indexOf(b) === -1 && list2.push(b)) || 1) && list2        , [])        .map(bId => json.behaviors[bId]);
Here I need to take multiple arrays of id’s, flatten them, remove duplicates, then map in their respective obje…