Warning Deprecated Ember add-on!
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:
dirty
dirtyAttributes
dirtyRelationships
dirtyProperties
hasDirtyRelationship
hasDirtyAttribute
${propertyName}Dirty
isDirty()
rollback()
- Ember.js v2.18 or above
- Ember CLI v2.13 or above
ember install ember-dirtier
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
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']
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']
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']
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
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
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
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 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
git clone <repository-url>
cd ember-dirtier
npm install
ember test
– Runs the test suite on the current Ember versionember test --server
– Runs the test suite in "watch mode"ember try:each
– Runs the test suite against multiple Ember versions
ember serve
- Visit the dummy application at http://localhost:4200.
For more information on using ember-cli, visit https://ember-cli.com/.
License This project is licensed under the MIT License.