-
Notifications
You must be signed in to change notification settings - Fork 2
/
get-mutable-attributes.js
40 lines (34 loc) · 1.05 KB
/
get-mutable-attributes.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
39
40
import Ember from 'ember';
import semver from 'semver';
// Glimmer starts from v2.10
const isGlimmer = semver.gte(Ember.VERSION, '2.10.0');
let getMutValue;
if (isGlimmer) {
// The module location before v3.2
let libPath = 'ember-views/compat/attrs';
if (semver.gte(Ember.VERSION, '3.6.0')) {
libPath = '@ember/-internals/views/lib/compat/attrs';
} else if (semver.gte(Ember.VERSION, '3.2.0')) {
libPath = 'ember-views/lib/compat/attrs';
}
const { MUTABLE_CELL } = Ember.__loader.require(libPath);
getMutValue = value => {
if (value && value[MUTABLE_CELL]) {
return value.value;
} else {
return value;
}
};
} else {
getMutValue = Ember.__loader.require('ember-htmlbars/hooks/get-value')[
'default'
];
}
// Borrowing this from ember-cli-react.
// https://github.com/AltSchool/ember-cli-react/blob/master/addon/utils/get-mutable-attributes.js
export default function getMutableAttributes(attrs) {
return Object.keys(attrs).reduce((acc, attr) => {
acc[attr] = getMutValue(attrs[attr]);
return acc;
}, {});
}