Code Monkey home page Code Monkey logo

ember-dirtier's Introduction

Build Status npm version Ember Observer Score

ember-dirtier

This addon extends ember-data by providing dirty tracking for the following:

  • Nested arrays
  • Nested object
  • Relationships
  • Transform types

In addition, it adds the following properties and functions to the DS.model class:

Properties

  • dirty
  • dirtyAttributes
  • dirtyRelationships
  • dirtyProperties
  • hasDirtyRelationship
  • hasDirtyAttribute
  • ${propertyName}Dirty

Functions

  • isDirty()
  • rollback()

Compatibility

  • Ember.js v2.18 or above
  • Ember CLI v2.13 or above

Installation

ember install ember-dirtier

Properties

dirty

Returns true if any attribute or relationship is dirty, otherwise returns false.

const artist = this.get('store').createRecord('artist');

artist.set('name', 'john');

debug(artist.get('dirty)); // true

dirtyAttributes

Returns an array of dirty attributes

const artist = this.get('store').createRecord('artist');

artist.set('name', 'john');
artist.set('genre', 'country');

debug(artist.get('dirtyAttributes')); // ['genre', 'name']

dirtyRelationships

Returns an array of dirty relationships

const artist = this.get('store').createRecord('artist');
const album = this.get('store').createRecord('album');
const albums = A([]);

album.set('name', 'country road');
albums.pushObject(album);

artist.set('name', 'john');
artist.set('genre', 'country');
artist.set('albums', albums);

debug(artist.get('dirtyRelationships')); // ['albums']

dirtyProperties

Returns an array of dirty properties

const artist = this.get('store').createRecord('artist');
const album = this.get('store').createRecord('album');
const albums = A([]);

album.set('name', 'country road');
albums.pushObject(album);

artist.set('name', 'john');
artist.set('genre', 'country');
artist.set('albums', albums);

debug(artist.get('dirtyProperties')); // ['albums', 'genre', 'name']

hasDirtyAttribute

Returns true if at least one attribute is dirty, otherwise returns false.

const artist = this.get('store').createRecord('artist');

artist.set('name', 'john');
artist.set('genre', 'country');

debug(artist.get('hasDirtyAttribute')); // true

hasDirtyRelationship

Returns true if at least one relationship is dirty, otherwise returns false

const artist = this.get('store').createRecord('artist');
const album = this.get('store').createRecord('album');
const albums = A([]);

album.set('name', 'country road');
albums.pushObject(album);

artist.set('name', 'john');
artist.set('genre', 'country');
artist.set('albums', albums);

debug(artist.get('hasDirtyRelationship')); // true

${propertyName}Dirty

Returns true if a property is dirty, otherwise returns false.

This is useful when you want to display a visual indicator when a field has been touched.

const artist = this.get('store').createRecord('artist');
const album = this.get('store').createRecord('album');
const albums = A([]);

album.set('name', 'country road');
albums.pushObject(album);

artist.set('name', 'john');
artist.set('genre', 'country');
artist.set('albums', albums);

debug(artist.get('nameDirty')); // true
debug(artist.get('genreDirty')) // true
debug(artist.get('albumsDirty')) // true

Functions

isDirty()

Returns true if model is dirty, otherwise returns false.

const artist = this.get('store').createRecord('artist');

artist.set('name', 'john');

debug(artist.isDirty()); // true

rollback()

Rollback the model. This will rollback the model and all its associated relationships.

const artist = this.get('store').createRecord('artist');
const album = this.get('store').createRecord('album');
const albums = A([]);

album.set('name', 'country road');
albums.pushObject(album);

artist.set('name', 'john');
artist.set('genre', 'country');
artist.set('albums', albums);

artist.rollback();

debug(artist.get('name')); // undefined
debug(artist.get('genre')); // undefined
debug(album.get('name')); // undefined

Installation

  • git clone <repository-url>
  • cd ember-dirtier
  • npm install

Running tests

  • ember test – Runs the test suite on the current Ember version
  • ember test --server – Runs the test suite in "watch mode"
  • ember try:each – Runs the test suite against multiple Ember versions

Running the dummy application

For more information on using ember-cli, visit https://ember-cli.com/.

License This project is licensed under the MIT License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.