From 0a351a51f1db35b2c9e3744dbddf6c9dd121212f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdussamed=20ULUTA=C5=9E?= Date: Sun, 22 Jan 2023 17:23:53 +0300 Subject: [PATCH] Clone Render element --- core.js | 58 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/core.js b/core.js index 1e2708e..4acf176 100644 --- a/core.js +++ b/core.js @@ -68,7 +68,7 @@ else if(typeof data.companent == "function") { let companent = RenderCompanent(data); - elem = RenderElement(null, companent) + elem = RenderCompanentScope(null, companent) } else if(typeof data.companent == "string") { @@ -88,7 +88,7 @@ } else { - RenderElement(elem, companent); + RenderCompanentScope(elem, companent); } } } @@ -127,7 +127,7 @@ } else { - RenderElement(elem, companent) + RenderCompanentScope(elem, companent) } } }else{ @@ -139,7 +139,7 @@ } else { - RenderElement(elem, companent) + RenderCompanentScope(elem, companent) } } } @@ -151,14 +151,14 @@ if(parent) { for (const vdata of data.flat(Infinity)) { - RenderElement(parent, vdata) + RenderCompanentScope(parent, vdata) }; } else { let d = document.createDocumentFragment(); for (const vdata of data.flat(Infinity)) { - RenderElement(d, vdata) + RenderCompanentScope(d, vdata) }; elem = d; } @@ -178,13 +178,42 @@ } } - function RenderCompanent(data) + function RenderCompanentScope(data) { useCompanent(data); let result = data.companent(data.props); useCompanent(undefined); return result; + }; + function clone(original) + { + if(Array.isArray(original)) + { + let e = []; + for (const original of original) { + // Klonlanabilirlik + } + } } + function checkSyncRender(data) + { + // İki kompanentin farkına bakılmalı ve yeniden çizilmeleri gerekiyor + } + function scheduleRender(data) + { + if(scheduleRender.planned) + { + scheduleRender.items.push(data); + return; + }; + requestAnimationFrame(()=>{ + scheduleRender.planned = false; + checkSyncRender(data) + }); + scheduleRender.planned = true; + }; + scheduleRender.planned = false; + scheduleRender.items = []; function é(a,b) { if(a instanceof Array) @@ -228,11 +257,15 @@ case "in":{ if(a[index] instanceof Array) { - props.children = a[index].map(é); + props.children = a[index].map((child) => { + let item = é(child); + item.parent = t; + return item; + }); }else{ - props.children = [ - é(a[index]) - ] + let child = é(a[index]); + child.parent = t; + props.children = [child] } break }; @@ -296,7 +329,8 @@ if(!Object.is(newValue, value)) { companent._state[id] = value; - return companent._render = true; + companent._render = true; + scheduleRenderCompanent(companent); } } ]