-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.js
27 lines (24 loc) · 859 Bytes
/
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
'use strict';
const lazy = (importedModule, importFn, moduleId) =>
importedModule === undefined ? importFn(moduleId) : importedModule;
module.exports = importFn => {
return moduleId => {
let importedModule;
const handler = {
get: (target, property) => {
importedModule = lazy(importedModule, importFn, moduleId);
return Reflect.get(importedModule, property);
},
apply: (target, thisArgument, argumentsList) => {
importedModule = lazy(importedModule, importFn, moduleId);
return Reflect.apply(importedModule, thisArgument, argumentsList);
},
construct: (target, argumentsList) => {
importedModule = lazy(importedModule, importFn, moduleId);
return Reflect.construct(importedModule, argumentsList);
}
};
// eslint-disable-next-line prefer-arrow-callback
return new Proxy(function () {}, handler);
};
};