Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jasiukiewicztymon authored Sep 30, 2022
1 parent ebb7f83 commit 3ee8aac
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ class vDOM {
// HTML 5 syntaxe requestemenets
SELF_CLOSE = ['base', 'meta', 'link', 'br', 'hr', 'img', 'area', 'input', 'col', 'param', 'wbr']

childToDOM(el) {
el.childs.forEach(childEl => {
this.childToDOM(childEl)
});
childToDOM(idx, tmpDOM) {
if (tmpDOM[idx].type == 'text') {
return 0;
}
var totChilds = tmpDOM[idx].opt.childs.length;

for (var i = 0; i < tmpDOM[idx].opt.childs.length; i++) {
totChilds += this.childToDOM(tmpDOM[idx].opt.childs[i], tmpDOM)
tmpDOM[idx].opt.childs[i] = tmpDOM[tmpDOM[idx].opt.childs[i]];
}

return totChilds;
}
HtmlTovDOM(html) {
HtmlTovDOM(html = '') {
// delete comments
html = html.replace(/<\!\-\-.*\-\->/g, '');
// reset DOM
Expand All @@ -26,6 +34,11 @@ class vDOM {
}
}

/*
||========================||
|| TEST UNIT ||
||========================||
tmpDOM = [
{ type: 'tag', name: 'div', opt: { args: [], childs: [ 1, 2 ] } },
{ type: 'tag', name: 'p', opt: { args: [], childs: [ 3 ] } },
Expand All @@ -34,10 +47,18 @@ class vDOM {
{ type: 'tag', name: 'b', opt: { args: [], childs: [ 5 ] } },
{ type: 'text', content: 'some bold text' }
]
*/

// link
for (var i = 0; i < tmpDOM.length; i++) {

var inc = this.childToDOM(i, tmpDOM);
this.virtualDOM.push(tmpDOM[i]);
i += inc;
}

// console.log(this.virtualDOM);
}
}

/*var vdom = new vDOM();
vdom.HtmlTovDOM();*/

0 comments on commit 3ee8aac

Please sign in to comment.