Shardjs, soma.js, jsprops

Alex R. Young





libraries testing node browser

Shardjs, soma.js, jsprops

Posted by Alex R. Young on .

libraries testing node browser

Shardjs, soma.js, jsprops

Posted by Alex R. Young on .


Shardjs (License: MIT) by Francesco Sullo is a module for managing keys of up to 3844 Redis nodes. The author was inspired by Sharding and IDs at Instagram where the Instagram developers discuss a solution to generating unique IDs at scale.

To get around the lack of 64-bit integers in JavaScript, the author has opted to use 62-bit strings. He discusses his algorithm for generating unique keys and where the number 3844 comes from in the project's readme:

The advantage of this approach is that since all the keys generated at the same millisecond will go on the same virtual shard and there is the incremental sequence, we can mantain the key well sorted by time.


soma.js (GitHub: somajs / somajs, License: MPL) by Romuald Quantin is a new MVC framework that uses the observer pattern with native events, and the command pattern, with the ultimate goal of encouraging development of decoupled modules:

The command pattern aims to encapsulate method invocation, requests or operations into a single object and gives you the ability to both parameterize and pass method calls around that can be executed at your discretion. In addition, it enables you to decouple objects invoking the action from the objects which implement them, giving you a greater degree of overall flexibility in swapping out concrete 'classes'.

-- Addy Osmani on the command pattern

In soma.js applications, there are wires, models, views, and commands. Wires are used to represent the logic of an application and coordinate between other elements of the framework. Models don't necessarily imply a particular storage solution, they're more like a convention for integrating with other solutions like localStorage or Knockout -- there's a demo showing how to use soma.js with Knockout's data bindings.

The project's website includes demos and a tutorial that explain how everything works.


jsprops (License: MIT) by Tobiasz Cudnik adds class-based properties to prototypes, the goal being to reduce redundancy when copying properties to instances. It also includes inheritance-based signalling.

Tobiasz has included CoffeeScript and JavaScript examples, but I've reproduced the JavaScript one here because it's a little bit easier to understand:

var property = require('jsprops').property;

function Klass() {}

Klass.prototype.foo = property('foo');  
Klass.prototype.bar = property('bar', null, 'def_value');  
Klass.prototype.baz = property('baz', {  
  set: function(set, val) {
    set(val.replace(/a/, 'b'));

The project comes with tests that further illustrate the intended usage.