diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b0c98a8 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "deno.cacheOnSave": true, + "deno.codeLens.test": true +} \ No newline at end of file diff --git a/proxy.js b/proxy.js index d71ecd4..60ae474 100644 --- a/proxy.js +++ b/proxy.js @@ -4,14 +4,22 @@ /** @type {(obj:T, key:string)=>T} */ const Deep =(obj, key)=> { + const proxInner =(context, key)=> new Proxy({}, { get(_, prop) { - const path = key+" . "+prop; - console.log(path, "accessed!"); - const value = context[key]; - - return proxInner(value, path); + if(typeof prop === "string") + { + const path = key+" . "+prop; + console.log(path, "accessed!"); + const value = context[prop]; + + return proxInner(value, path); + } + else + { + return context[prop] + } } }); diff --git a/proxy.test.ts b/proxy.test.ts index e3323f2..a86ebae 100644 --- a/proxy.test.ts +++ b/proxy.test.ts @@ -4,6 +4,7 @@ import Deep from "./proxy.js"; Deno.test("proxy", ()=>{ const d1 = Deep({name:"seth", age:41, tags:[]}, "p1"); - const dig = d1.name.other; - const dig2 = dig.so.deep; + const dig = d1.name; + //const dig2 = dig.so.deep; + }); \ No newline at end of file