Skip to content

Commit

Permalink
Merge pull request #4324 from pangratz/doc-changedAttributes
Browse files Browse the repository at this point in the history
[DOC beta] Clarify DS.Model#changedAttributes()
  • Loading branch information
bmac committed Apr 14, 2016
2 parents 6bdeb31 + e5b3268 commit 9cbad2b
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions addon/-private/system/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,21 +592,40 @@ var Model = Ember.Object.extend(Ember.Evented, {
Returns an object, whose keys are changed properties, and value is
an [oldProp, newProp] array.
The array represents the diff of the canonical state with the local state
of the model. Note: if the model is created locally, the canonical state is
empty since the adapter hasn't acknowledged the attributes yet:
Example
```app/models/mascot.js
import DS from 'ember-data';
export default DS.Model.extend({
name: attr('string')
name: attr('string'),
isAdmin: attr('boolean', {
defaultValue: false
})
});
```
```javascript
var mascot = store.createRecord('mascot');
mascot.changedAttributes(); // {}
mascot.set('name', 'Tomster');
mascot.changedAttributes(); // {name: [undefined, 'Tomster']}
mascot.changedAttributes(); // { name: [undefined, 'Tomster'] }
mascot.set('isAdmin', true);
mascot.changedAttributes(); // { isAdmin: [undefined, true], name: [undefined, 'Tomster'] }
mascot.save().then(function() {
mascot.changedAttributes(); // {}
mascot.set('isAdmin', false);
mascot.changedAttributes(); // { isAdmin: [true, false] }
});
```
@method changedAttributes
Expand Down

0 comments on commit 9cbad2b

Please sign in to comment.