forked from nullstack/nullstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstanceProxyHandler.js
More file actions
25 lines (23 loc) · 966 Bytes
/
instanceProxyHandler.js
File metadata and controls
25 lines (23 loc) · 966 Bytes
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
//import {generateContext} from './context';
const instanceProxyHandler = {
get(target, name) {
/*if(target[name] === undefined && typeof(target.constructor[name]) === 'function' && name !== 'constructor') {
return async function(params = {}) {
const request = target._request();
const response = target._response();
const context = generateContext({request, response, ...params});
return await target.constructor[name](context);
}
//Object.defineProperty(detour, 'name', {value: name});
//target[name] = detour;
} else*/
if(typeof(target[name]) == 'function' && !target[name].name.startsWith('_') && name !== 'constructor') {
return (args) => {
const context = target._scope.generateContext({...target._attributes, ...args, self: target._self});
return target[name](context);
}
}
return Reflect.get(...arguments);
}
}
export default instanceProxyHandler;