deep-proxy #1
							
								
								
									
										4
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							| @ -1,4 +0,0 @@ | ||||
| { | ||||
|     "deno.cacheOnSave": true, | ||||
|     "deno.codeLens.test": true | ||||
| } | ||||
| @ -6,5 +6,8 @@ | ||||
|             "DOM" | ||||
|         ], | ||||
|         "types": ["./types.d.ts"] | ||||
|     }, | ||||
|     "imports": { | ||||
|         "entry":"./app.js" | ||||
|     } | ||||
| } | ||||
							
								
								
									
										18
									
								
								index.html
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								index.html
									
									
									
									
									
								
							| @ -9,6 +9,22 @@ | ||||
|         <script src="https://cdn.jsdelivr.net/gh/vanjs-org/van/public/van-1.5.3.nomodule.min.js"></script> | ||||
|         <script src="https://cdn.jsdelivr.net/npm/vanjs-ext@0.6.2/dist/van-x.nomodule.min.js"   ></script> | ||||
|         <script src="./gale.js"></script> | ||||
|         <script type="module" src="app.js"></script> | ||||
|         <script> | ||||
|             ( | ||||
|                 (root="/")=>fetch(root+"deno.json") | ||||
|                 .then(text=>text.json()) | ||||
|                 .then(json=>{ | ||||
|                     const n=(t,e)=>{let n=document.createElement("script");n.type=t,n.textContent=e,document.head.appendChild(n)}; | ||||
|                     const imports = json.imports; | ||||
|                     for(let n in imports) | ||||
|                     { | ||||
|                         const path=imports[n]; | ||||
|                         path.startsWith("./")&&(imports[n]=root+path.substring(2)) | ||||
|                     } | ||||
|                     n("importmap",JSON.stringify({imports})), | ||||
|                     n("module",'import "entry"; ') | ||||
|                 }) | ||||
|             )(); | ||||
|         </script> | ||||
|     </body> | ||||
| </html> | ||||
							
								
								
									
										40
									
								
								proxy.js
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								proxy.js
									
									
									
									
									
								
							| @ -1,40 +0,0 @@ | ||||
| //const person = van.state({name:"seth", age:41});
 | ||||
| //console.log(Object.hasOwn(person, "rawVal"));
 | ||||
| 
 | ||||
| /** @type {<T>(obj:T, key:string)=>T} */ | ||||
| const Deep =(obj, key)=> | ||||
| { | ||||
| 
 | ||||
|     const proxInner =(context, key)=> new Proxy({}, { | ||||
|         get(_, prop) | ||||
|         { | ||||
|             if(typeof prop === "string") | ||||
|             { | ||||
|                 const path = key+" . "+prop; | ||||
|                 console.log(path, "accessed!"); | ||||
|                 const value = context[prop]; | ||||
|      | ||||
|                 return proxInner(value, path); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return context[prop] | ||||
|             } | ||||
|         } | ||||
|     }); | ||||
| 
 | ||||
|     const proxOuter = new Proxy({}, { | ||||
|         get(_, prop) | ||||
|         { | ||||
|             return proxInner(obj, prop); | ||||
|         }, | ||||
|         set(_, prop, val) | ||||
|         { | ||||
|             obj[prop] = val; | ||||
|         } | ||||
|     }); | ||||
| 
 | ||||
|     return proxOuter; | ||||
| } | ||||
| 
 | ||||
| export default Deep; | ||||
| @ -1,10 +0,0 @@ | ||||
| import * as assert from "jsr:@std/assert"; | ||||
| import Deep from "./proxy.js"; | ||||
| 
 | ||||
| Deno.test("proxy", ()=>{ | ||||
| 
 | ||||
|     const d1 = Deep({name:"seth", age:41, tags:[]}, "p1"); | ||||
|     const dig = d1.name; | ||||
|     //const dig2 = dig.so.deep;
 | ||||
| 
 | ||||
| }); | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user