Util.js
1.3 KB
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
define(function(require) {
'use strict';
function mergeStatic(startPtr, endPtr, obj, fieldName, filterFunc) {
var result = filterFunc(obj);
var ptr = startPtr;
while (true) {
result = _.extend(result, filterFunc(_.result(ptr, fieldName)));
if (ptr === endPtr) {
break;
}
ptr = ptr.__super__.constructor;
}
return result;
}
return {
getField: function getField(obj, key) {
return obj[key];
},
setField: function getField(obj, key, value) {
return obj[key] = value;
},
getItemKeyAccessor: function getItemKeyAccessor(item) {
return item.get('key');
},
mergeStaticProps: function mergeStaticProps(startPtr, endPtr, obj, fieldName) {
return mergeStatic(startPtr, endPtr, obj, fieldName, _.identity);
},
mergeStaticSets: function mergeStaticSets(startPtr, endPtr, obj, fieldName) {
return _.keys(mergeStatic(startPtr, endPtr, obj, fieldName, function arrayToMap(array) {
var result = {};
_.each(array, function(value) {
result[value] = true;
});
return result;
}));
},
};
});