refac: SammoAPI에서 인자, 반환 타입을 사전 지정 가능

This commit is contained in:
2022-03-25 22:48:34 +09:00
parent da91d66179
commit 11e28b7a87
5 changed files with 31 additions and 18 deletions
+24
View File
@@ -0,0 +1,24 @@
export function APIPathGen(obj, callback, path) {
return new Proxy(obj, {
get(target, key) {
let nextPath;
if (path === undefined) {
nextPath = [key];
}
else {
nextPath = path;
nextPath.push(key);
}
if (!(key in target)) {
throw `${nextPath} is not exists`;
}
const next = target[key];
if (typeof (next) === 'function') {
return callback(nextPath);
}
return APIPathGen(next, callback, nextPath);
}
})
}