Comparing version 0.0.6 to 0.0.7
{ | ||
"name": "realdom", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"author": "Fedot Kriutchenko <fodyadev@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "", |
@@ -5,36 +5,29 @@ import { runWithState, getCurrentHandler } from './state.js'; | ||
const symbol = Symbol(); | ||
function builder(effect) { | ||
let names = []; | ||
const tasks = []; | ||
const Builder = (effect, tasks=[], names=[]) => new Proxy( | ||
(...args) => args[0] === symbol | ||
? (args[0] = tasks, effect(...args)) | ||
: Builder(effect, [...tasks, { names, args }], []), | ||
{ get: (_, k) => k === symbol | ||
? effect[k] | ||
: Builder(effect, tasks, [...names, k]) | ||
}); | ||
const call = (...args) => { | ||
if (args[0] === symbol) { | ||
const a = args.slice(1); | ||
let res; | ||
for (const t of tasks) res ??= effect(t.names, t.args, ...a); | ||
return res; | ||
} else { | ||
tasks.push({ names, args }); | ||
names = []; | ||
} | ||
return p; | ||
const elementBuilder = func => { | ||
const effect = (tasks, node, init) => { | ||
let res; | ||
for (const {names, args} of tasks) res ??= func(args, node, init); | ||
return res; | ||
} | ||
const get = (_, k) => { | ||
if (k === symbol) return effect[k]; | ||
names.push(k); | ||
return p; | ||
} | ||
let p; return p = new Proxy(call, { get }); | ||
effect[symbol] = 1; | ||
return Builder(effect); | ||
} | ||
export const Operator = (reactive, func) => { | ||
const effect = (names, args, node, init) => { | ||
const r = typeof reactive == 'function' ? reactive(args) : reactive; | ||
if (init && !r || r) func(node, names, args); | ||
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); | ||
} | ||
} | ||
effect[symbol] = 2; | ||
return new Proxy( | ||
(...a) => builder(effect)(...a), | ||
{ get: (_, k) => builder(effect)[k] } | ||
); | ||
return Builder(effect); | ||
} | ||
@@ -46,7 +39,3 @@ | ||
const elementBuilder = effect => { | ||
effect[symbol] = 1; | ||
return builder(effect); | ||
} | ||
export const Element = tag => elementBuilder((_, content, node, init) => { | ||
export const Element = tag => elementBuilder((content, node, init) => { | ||
const node_ = node; | ||
@@ -53,0 +42,0 @@ if (!node && (init = true)) switch (tag) { |
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
3577
67