Comparing version 0.0.8 to 0.0.9
{ | ||
"name": "realdom", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"author": "Fedot Kriutchenko <fodyadev@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "", |
@@ -0,5 +1,6 @@ | ||
import { r } from './state.js'; | ||
import { argsToArray, isReactive, toString, kebab } from './common.js'; | ||
const symbol = Symbol(); | ||
const Builder = (effect, tasks=[], names=[]) => new Proxy( | ||
export const Builder = (effect, tasks=[], names=[]) => new Proxy( | ||
(...args) => args[0] === symbol | ||
@@ -12,2 +13,3 @@ ? (args[0] = tasks, effect(...args)) | ||
}); | ||
Builder.launch = (f, ...a) => f(symbol, ...a); | ||
@@ -23,7 +25,7 @@ const elementBuilder = func => { | ||
} | ||
export const Operator = (reactive, func) => { | ||
export const Operator = (func) => { | ||
const effect = (tasks, node, init) => { | ||
for (const {names, args} of tasks) { | ||
const r = typeof reactive == 'function' ? reactive(args) : reactive; | ||
if (init && !r || r) func(node, names, args); | ||
const reactive = isReactive(args); | ||
if (init || reactive) r.effect(() => func(node, names, args)); | ||
} | ||
@@ -35,3 +37,3 @@ } | ||
const textContent = Operator(isReactive, (node, _, args) => { | ||
const textContent = Operator((node, _, args) => { | ||
node.textContent = toString(args); | ||
@@ -41,3 +43,2 @@ }); | ||
export const Element = tag => elementBuilder((content, node, init) => { | ||
const node_ = node; | ||
if (!node && (init = true)) switch (tag) { | ||
@@ -51,5 +52,8 @@ case '': node = document.createTextNode(''); break; | ||
let child = init ? null : node.firstChild; | ||
const append = item => node.appendChild(item(symbol, null, init)); | ||
const apply = item => item(symbol, node, init); | ||
const hydrate = item => (item(symbol, child, init), child = child.nextSibling); | ||
const append = item => node.appendChild(Builder.launch(item, null, init)); | ||
const apply = item => Builder.launch(item, node, init); | ||
const hydrate = item => { | ||
Builder.launch(item, child, init); | ||
child = child.nextSibling; | ||
} | ||
@@ -71,6 +75,7 @@ for (const item of argsToArray(content)) switch (item[symbol]) { | ||
return (...args) => { | ||
const node = func(...args)(symbol, tmpl ? tmpl.cloneNode(true) : null); | ||
tmpl ??= node; | ||
return node; | ||
const elem = func(...args); | ||
return !tmpl | ||
? tmpl = Builder.launch(elem, null) | ||
: Builder.launch(elem, tmpl.cloneNode(true)); | ||
} | ||
} |
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
3587
68