emberjs/ember.js — Issue #352: setProperties should use changeProperties
Author: lukemelia
Created: 2012-01-06 15:35:00+00:00
State: open

While answering a question on Stack Overflow (http://stackoverflow.com/questions/8752805/emberjs-set-multiple-properties-at-once), I noticed that the implementation of setProperties in Ember.Observable doesn't ensure the call to endProperty changes:

```javascript
/**
To set multiple properties at once, call setProperties
with a Hash:

record.setProperties({ firstName: 'Charles', lastName: 'Jolley' });

@param {Hash} hash the hash of keys and values to set
@returns {Ember.Observable}
*/
setProperties: function(hash) {
Ember.beginPropertyChanges(this);
for(var prop in hash) {
if (hash.hasOwnProperty(prop)) set(this, prop, hash[prop]);
}
Ember.endPropertyChanges(this);
return this;
},
```

My expectation on opening the code was that it was going to use Ember.changeProperties, which calls endPropertyChanges in a finally block.

```javascript
Ember.changeProperties = function(cb){
Ember.beginPropertyChanges();
try {
cb();
} finally {
Ember.endPropertyChanges();
}
};

```

Is there any reason not to use changeProperties here? If I get some +1s, I will make a pull request.