MCPcopy Create free account
hub / github.com/Lobos/react-ui / getFunc

Method getFunc

src/FilterItem.js:46–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44 }
45
46 getFunc () {
47 let options = this.props.options,
48 name = this.props.name,
49 value = this.props.value,
50 op = this.props.op,
51 func = function () {},
52 filter = options[this.props.index];
53
54 if (options.type === 'integer' || options.type === 'number') {
55 value = parseFloat(value);
56 }
57
58 if (filter[op]) {
59 return function (d) {
60 return filter[op](d, value);
61 };
62 }
63
64 switch (op) {
65 case '=':
66 func = (d) => { return d[name].toString() === value.toString(); };
67 break;
68 case 'like':
69 func = (d) => { return d[name].indexOf(value) >= 0; };
70 break;
71 case '>':
72 func = (d) => { return d[name] > value; };
73 break;
74 case '>=':
75 func = (d) => { return d[name] >= value; };
76 break;
77 case '<':
78 func = (d) => { return d[name] < value; };
79 break;
80 case '<=':
81 func = (d) => { return d[name] <= value; };
82 break;
83 case 'in':
84 func = (d) => { return value.split(',').indexOf(d[name].toString()) >= 0; };
85 break;
86 case 'not in':
87 func = (d) => { return value.split(',').indexOf(d[name].toString()) < 0; };
88 break;
89 }
90
91 return func;
92 }
93
94 remove () {
95 // setTimeout wait parent clickaway completed

Callers 1

onFilterFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected