0.0.1 • Published 4 months ago

frosty v0.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
4 months ago

frosty

Build Status

Browser Support

Introduction

Define frozen properties on objects:

  • a frozen property can be set to an non-undefined value just once
  • any further attempts to change its value will throw an Error

Install

Via NPM.

npm install --save frosty

Usage

Canonical example of an immutable type:

import frosty from 'frosty'

class ImmutableType {
  constructor(property1, property2) {
    this.property1 = property1
    this.property2 = property2
  }
}

frosty.freeze(ImmutableType.prototype, 'property1', 'property2')

undefined isn't a valid value for a frozen property:

// throws "'property2' should be defined"
let immutable_type = new ImmutableType('my_property1', undefined)

Frozen properties are read-only, and can only be set once:

let immutable_type = new ImmutableType('my_property1', true)

immutable_type.property1 // 'my_property1'
immutable_type.property1 = 'another_property1' // "throws 'my_property1' is immutable"

See the tests for more examples.

Development

In ES6 & Babel.

Transpile:

$ node_modules/.bin/gulp build

Test:

$ sudo chmod +x test.js
$ npm test

LICENSE

MIT © 2015, Victor Alvarez

0.0.1

4 months ago

1.0.9

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago