Experiences with seamless-immutable

On our data the "dev" version (that actually does freeze data etc.) was 2-3 slower than the (nearly "noop") prod version - f.ex. 2200 ms x 800 ms. => it is great there are both the dev and prod versions

Modifying data with seamless-immutable


In [4]:
var Immutable = require('seamless-immutable');

Imutable arrays

Push, unshift => concat


In [14]:
var original = Immutable([2]);
original.concat([3]);


Out[14]:
[ 2, 3 ]

In [15]:
Immutable([1]).concat(original);


Out[15]:
[ 1, 2 ]

Pop => slice


In [6]:
Immutable([1]).slice(0,-1);


Out[6]:
[]

Other: splice OK, sort :(, ...

Impractical

Mutating nested structures is cumbersome. F.ex. here we want to add a new "event" to a log at the last path:


In [16]:
var report = Immutable([{path: "/", log: []},{path: "/last", log: []}]);
// Update to [{path: "/", log: ["new event"]}]; It would be easy if we had updateIn and a curried concat:
// var updatedReport = updateIn(report, [report.length - 1, log], concat(["new event"]))
var oldEntry = report[report.length-1];
/*var updatedReport =*/ report.slice(0,-1).concat([
    oldEntry.merge({log: oldEntry.log.concat(["new event"])})
]);


Out[16]:
[ { path: '/', log: [] },
  { path: '/last', log: [ 'new event' ] } ]