deep-proxy #1
							
								
								
									
										4
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					    "deno.cacheOnSave": true,
 | 
				
			||||||
 | 
					    "deno.codeLens.test": true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										29
									
								
								proxy.js
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								proxy.js
									
									
									
									
									
								
							@ -1,17 +1,34 @@
 | 
				
			|||||||
const person = van.state({name:"seth", age:41});
 | 
					//const person = van.state({name:"seth", age:41});
 | 
				
			||||||
console.log(Object.hasOwn(person, "rawVal"));
 | 
					//console.log(Object.hasOwn(person, "rawVal"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const isLeaf =(obj, key)=>
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    const type = typeof arg;
 | 
				
			||||||
 | 
					    if(arg == null || type == "")
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** @type {<T>(obj:T, key:string)=>T} */
 | 
					/** @type {<T>(obj:T, key:string)=>T} */
 | 
				
			||||||
const Deep =(obj, key)=>
 | 
					const Deep =(obj, key)=>
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const proxInner =(context, key)=> new Proxy({}, {
 | 
					    const proxInner =(context, key)=> new Proxy({}, {
 | 
				
			||||||
        get(_, prop)
 | 
					        get(_, prop)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            const path = key+" . "+prop;
 | 
					            if(typeof prop === "string")
 | 
				
			||||||
            console.log(path, "accessed!");
 | 
					            {
 | 
				
			||||||
            const value = context[key];
 | 
					                const path = key+" . "+prop;
 | 
				
			||||||
 | 
					                console.log(path, "accessed!");
 | 
				
			||||||
 | 
					                const value = context[prop];
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
            return proxInner(value, path);
 | 
					                return proxInner(value, path);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                return context[prop]
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -4,6 +4,7 @@ import Deep from "./proxy.js";
 | 
				
			|||||||
Deno.test("proxy", ()=>{
 | 
					Deno.test("proxy", ()=>{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const d1 = Deep({name:"seth", age:41, tags:[]}, "p1");
 | 
					    const d1 = Deep({name:"seth", age:41, tags:[]}, "p1");
 | 
				
			||||||
    const dig = d1.name.other;
 | 
					    const dig = d1.name;
 | 
				
			||||||
    const dig2 = dig.so.deep;
 | 
					    //const dig2 = dig.so.deep;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user