Just-in-time immutability.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples/simple
src
test
.babelrc
.eslintignore
.eslintrc
.gitignore
.npmignore
.travis.yml
CHANGELOG.md
CODE_OF_CONDUCT.md
IceDam.gif
LICENSE.md
README.md
package.json
webpack.config.js

README.md

Friends don't let friends mutate.

What's This?

Ice Dam: a very lightweight library to freeze data. Data is frozen at the edge, where your Flux container sends it to views.

Why?

To prevent accidental mutation and bugs.

Show me the code!

For Redux, you wrap a component in a connect function. Its first argument is a selector.

function mapStateToProps(state)  {
  return {
    products: state.products
  };
}

var App = connect(mapStateToProps)(App)

Adding freeze will call Object.freeze in development

npm install --save icedam

import {makeFreezer} from 'icedam';
var freeze = makeFreezer();

function mapStateToProps(state)  {
  return freeze({
    products: state.products
  });
}

var App = connect(mapStateToProps)(App)

Demos

Screencast

What about an library for immutability?

Using an immutable library means commiting to using it throughout your stack. You'll have to change coding style, teach all your developers, and call toJS() when passing data. If your only concern is preventing views from mutating data, that might be too much.

What about speed?

In production: No cost. No freezing.

In dev (process.env.NODE_ENV === 'development'): when data structures change, cloning has a slight cost, usually well under a millisecond.

IceDam only clones objects when they have changed (!shallowEqual).

Image Credit: skekonk