Skip to content

Commit

Permalink
Merge pull request #3329 from pangratz/remove_reduce_computed_from_model
Browse files Browse the repository at this point in the history
Refactor `Errors#errorsByAttributeName` to not use Ember.reduceComputed
  • Loading branch information
igorT committed Jun 14, 2015
2 parents 73cb924 + 71fecd2 commit c093d72
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions packages/ember-data/lib/system/model/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,26 +109,12 @@ export default Ember.Object.extend(Ember.Enumerable, Ember.Evented, {
@type {Ember.MapWithDefault}
@private
*/
errorsByAttributeName: Ember.reduceComputed("content", {
initialValue: function() {
return MapWithDefault.create({
defaultValue: function() {
return Ember.A();
}
});
},

addedItem: function(errors, error) {
errors.get(error.attribute).pushObject(error);

return errors;
},

removedItem: function(errors, error) {
errors.get(error.attribute).removeObject(error);

return errors;
}
errorsByAttributeName: Ember.computed(function() {
return MapWithDefault.create({
defaultValue: function() {
return Ember.A();
}
});
}),

/**
Expand Down Expand Up @@ -234,6 +220,7 @@ export default Ember.Object.extend(Ember.Enumerable, Ember.Evented, {

messages = this._findOrCreateMessages(attribute, messages);
get(this, 'content').addObjects(messages);
get(this, 'errorsByAttributeName').get(attribute).addObjects(messages);

this.notifyPropertyChange(attribute);
this.enumerableContentDidChange();
Expand Down Expand Up @@ -297,6 +284,7 @@ export default Ember.Object.extend(Ember.Enumerable, Ember.Evented, {

var content = get(this, 'content').rejectBy('attribute', attribute);
get(this, 'content').setObjects(content);
get(this, 'errorsByAttributeName').delete(attribute);

this.notifyPropertyChange(attribute);
this.enumerableContentDidChange();
Expand Down Expand Up @@ -331,6 +319,7 @@ export default Ember.Object.extend(Ember.Enumerable, Ember.Evented, {
if (get(this, 'isEmpty')) { return; }

get(this, 'content').clear();
get(this, 'errorsByAttributeName').clear();
this.enumerableContentDidChange();

this.trigger('becameValid');
Expand Down

0 comments on commit c093d72

Please sign in to comment.