-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (36 loc) · 1.03 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
export default function untilLater() {
return new Proxy({
_functionCalls: []
}, {
get: (target, key) => {
if (key === "later") {
return (realObject) => {
Object.entries(target).forEach(([key, value]) => {
if (key.startsWith("_")) return;
realObject[key] = value;
});
target._functionCalls.forEach(({ key, args }) => {
realObject[key](...args);
});
return realObject;
};
} else {
return (...args) => {
target._functionCalls.push({ key, args });
};
}
},
set: (target, key, value) => {
target[key] = value;
return true;
}
});
}
const g = (() => {
if (typeof global !== "undefined") {
return global;
} else {
return window;
}
})();
g.untilLater = untilLater;