-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
72 lines (68 loc) · 1.89 KB
/
index.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import all from './methods/all';
import any from './methods/any';
import append from './methods/append';
import assoc from './methods/assoc';
import at from './methods/at';
import bsearch from './methods/bsearch';
import bsearchIndex from './methods/bsearchIndex';
import clear from './methods/clear';
import collect from './methods/collect';
import compact from './methods/compact';
import concat from './methods/concat';
import count from './methods/count';
import cycle from './methods/cycle';
import deleteMethod from './methods/delete';
import deleteAt from './methods/deleteAt';
import deleteIf from './methods/deleteIf';
import difference from './methods/difference';
import dig from './methods/dig';
import drop from './methods/drop';
import dropWhile from './methods/dropWhile';
import each from './methods/each';
import eachIndex from './methods/eachIndex';
const handlers = {
all,
any,
append,
assoc,
at,
bsearch,
bsearchIndex,
clear,
collect,
compact,
concat,
count,
cycle,
delete: deleteMethod,
deleteAt,
deleteIf,
difference,
dig,
drop,
dropWhile,
each,
eachIndex
};
export default function rbjs(toProxy) {
if (!(toProxy instanceof Array)) {
return toProxy;
}
return new Proxy(toProxy, {
get(target, property) {
if (property === '__rbjs__') {
return true;
} else if (handlers.hasOwnProperty(property)) {
const handler = handlers[property];
return (...args) => rbjs(handler(target, ...args));
} else if (typeof target[property] === 'function') {
return (...args) => rbjs(target[property](...args));
}
return rbjs(target[property]);
},
has(target, property) {
return (property in handlers)
|| (property in target);
}
});
}