Node package for immutable value objects
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
LICENSE
README.md
immute.js
package.json

README.md

Immute

Build Status Bitdeli Badge Description

Immute is a simple library intended for the creation of immutable value objects. If you want to know more about what immutable value objects are and why they a good thing have, please read the following article by Runway 7.

Installation

Immute is available from the NPM repository simply npm install immute or add immute as a dependency in your package.json file.

Usage

Creating immutable object constructor

var immute = require('immute');

var Cat = immute({
        name: "required",
        birthDate: "required",
        description: "optional"
    });

Object properties can be required or optional

var unknown = new Cat({birthDate: "02.03.32", description: "fat homeless cat"}); 
// ERROR: 'Required field missing from immutable object'

Object properties cannot be updated

var sheldon = new Cat({name: "sheldon", birthDate: "02.04.2013"}); //valid
sheldon.name = "Leonard"; // ERROR: 'Immutable value object. Property cannot be changed'

Objects are closed so no additional parameters can be added

var cuddles = new Cat({name: "cuddles", birthDate: "02.02.2012", description:"likes salmon"}); //valid
cuddles.status = "sleeping"; 

Object.keys(cuddles); // ['name','birthDate','description']