Skip to content
This repository has been archived by the owner on Mar 27, 2020. It is now read-only.

Immutable data structures for Ember.js (seamless-immutable)

License

Notifications You must be signed in to change notification settings

cyk/ember-seamless-immutable

Repository files navigation

Ember Seamless Immutable

Build Status npm version Ember Observer Score

"Immutable data structures which are backwards-compatible with normal Arrays and Objects" provided by the excellent Seamless Immutable library, wrapped and adapted for Ember.

⚠️ Experimental. A noop function is defined on all objects made immutable to circumvent Ember defining meta properties on them.

⚠️ Array prototype extension incompatibility. This add-on is incompatible with the Ember array prototype extension. For instructions on disabling prototype extensions consult the Ember guide.

Why Addon?

  • Seamless-immutable is imported from node_modules to Ember app (i.e., up-to-date, not bundled)
  • Seamless-immutable is configured to your Ember app environment
  • Immutable objects are made usable in Ember templates
  • Helper that makes properties passed to a component immutable

Read more about it in "Exploring Immutability in Ember.js"

Installation

ember install ember-seamless-immutable

Usage

import immutable from 'immutable';
import Ember from 'ember';

export default Ember.Route.extend({
  model() {
    return Ember.$.getJSON('/api/contacts').then(response => {
      return immutable(response.contacts);
    });
  }
});

The default export immutable is adapted for Ember. The original named export remains intact:

import { Immutable } from 'immutable';

See Seamless Immutable: API Overview.

Helper

{{contact-detail contact=(immutable contact)}}

An immutable contact object will be passed in to the component.

Running Tests

  • ember test
  • ember test --server