Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "realdom", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"author": "Fedot Kriutchenko <fodyadev@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "", |
import { runWithState, getCurrentHandler } from './state.js'; | ||
import { argsToArray, isReactive, kebab } from './common.js'; | ||
import { argsToArray, toString, kebab } from './common.js'; | ||
let tree = null; | ||
let treeSymbol = Symbol(); | ||
const symbol = Symbol(); | ||
export class Tree { | ||
@@ -17,3 +17,7 @@ list = [] | ||
case NodeOpen: | ||
const elem = document.createElement(item.tag); | ||
const elem = ( | ||
item.tag === '' | ||
? document.createTextNode('') | ||
: document.createElement(item.tag) | ||
); | ||
if (node) node.appendChild(elem); else this.tmpl = elem; | ||
@@ -27,4 +31,3 @@ node = nodes[l] = elem; | ||
case NodeText: | ||
const text = document.createTextNode(item.value); | ||
nodes[l - 1].appendChild(text); | ||
if (!item.rerender) node.textContent = item.value; | ||
break; | ||
@@ -74,3 +77,2 @@ case NodeClose: | ||
const symbol = Symbol(); | ||
function builder(effect) { | ||
@@ -90,3 +92,3 @@ let names = []; | ||
const get = (_, k) => { | ||
if (k === treeSymbol) return true; | ||
if (k === symbol) return true; | ||
names.push(k); | ||
@@ -122,18 +124,16 @@ return p; | ||
export const Element = (tag, ...content) => { | ||
const launch = () => { | ||
tree.list[tree.i++] ??= new NodeOpen( | ||
tag[0].toLowerCase() + kebab(tag.slice(1)) | ||
); | ||
for (const item of content) { | ||
switch (item[treeSymbol]) { | ||
case true: item(); break; | ||
default: (tree.list[tree.i++] ??= new NodeText(item)).update(item); | ||
} | ||
export const Element = tag => builder((_, content) => { | ||
tree.list[tree.i++] ??= new NodeOpen( | ||
!tag ? tag : tag[0].toLowerCase() + kebab(tag.slice(1)) | ||
); | ||
for (const item of argsToArray(content)) { | ||
if (typeof item == 'function' && item[symbol]) item(); | ||
else { | ||
tree.list[tree.i++] ??= new NodeOpen(''); | ||
(tree.list[tree.i++] ??= new NodeText(item)).update(item); | ||
tree.list[tree.i++] ??= new NodeClose(); | ||
} | ||
tree.list[tree.i++] ??= new NodeClose(); | ||
} | ||
launch[treeSymbol] = true; | ||
return launch; | ||
} | ||
tree.list[tree.i++] ??= new NodeClose(); | ||
}); | ||
@@ -140,0 +140,0 @@ export const Component = func => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4881