-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
set_properties.js
38 lines (32 loc) · 941 Bytes
/
set_properties.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { changeProperties } from 'ember-metal/property_events';
import { set } from 'ember-metal/property_set';
/**
Set a list of properties on an object. These properties are set inside
a single `beginPropertyChanges` and `endPropertyChanges` batch, so
observers will be buffered.
```javascript
var anObject = Ember.Object.create();
anObject.setProperties({
firstName: 'Stanley',
lastName: 'Stuart',
age: 21
});
```
@method setProperties
@param obj
@param {Object} properties
@return properties
@public
*/
export default function setProperties(obj, properties) {
if (!properties || typeof properties !== 'object') { return properties; }
changeProperties(() => {
var props = Object.keys(properties);
var propertyName;
for (var i = 0; i < props.length; i++) {
propertyName = props[i];
set(obj, propertyName, properties[propertyName]);
}
});
return properties;
}