Util.js
1.57 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
41
42
43
44
45
46
47
48
49
50
51
define(function(require) {
'use strict';
function mergeStatic(startPtr, endPtr, obj, fieldName, filterFunc) {
var result = filterFunc(obj);
var ptr = startPtr;
while (true) {
result = _.defaults(result, filterFunc(_.result(ptr, fieldName)));
if (ptr === endPtr) {
break;
}
ptr = ptr.__super__.constructor;
}
return result;
}
function preventDefault(e) {
if (e) {
e.preventDefault();
}
}
return {
preventDefault: preventDefault,
stepFalse: function stepFalse(e) {
preventDefault(e);
return false;
},
getField: function getField(obj, key) {
return obj[key];
},
setField: function getField(obj, key, value) {
obj[key] = value;
return 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;
}));
},
};
});