mini-van-plate
Advanced tools
Comparing version 0.4.2 to 0.5.0-perf.0
{ | ||
"name": "mini-van-plate", | ||
"version": "0.4.2", | ||
"version": "0.5.0-perf.0", | ||
"description": "A minimalist template engine for DOM generation and manipulation, working for both client-side and server-side rendering", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -47,15 +47,19 @@ /// <reference types="./van-plate.d.ts" /> | ||
const elementProto = { | ||
renderToBuf(buf) { | ||
buf.push(`<${this.name}${this.propsStr}>`) | ||
if (noChild[this.name]) return | ||
for (const c of this.children) { | ||
const plainC = plainValue(c) | ||
protoOf(plainC) === elementProto ? plainC.renderToBuf(buf) : buf.push(escape(plainC.toString())) | ||
} | ||
buf.push(`</${this.name}>`) | ||
}, | ||
render() { | ||
return noChild[this.name] ? | ||
`<${this.name}${this.propsStr}>` : | ||
`<${this.name}${this.propsStr}>${this.childrenStrs.join("")}</${this.name}>` | ||
} | ||
const buf = [] | ||
this.renderToBuf(buf) | ||
return buf.join("") | ||
}, | ||
} | ||
const toStr = children => children.map( | ||
c => { | ||
const plainC = plainValue(c) | ||
return protoOf(plainC) === elementProto ? plainC.render() : escape(plainC.toString()) | ||
}).join("") | ||
const tags = new Proxy((name, ...args) => { | ||
@@ -70,10 +74,8 @@ const [props, ...children] = protoOf(args[0] ?? 0) === objProto ? args : [{}, ...args] | ||
}).join("") | ||
const flattenedChildren = children.flat(Infinity).filter(c => c != null) | ||
return {__proto__: elementProto, name, propsStr, | ||
childrenStrs: flattenedChildren.length > 0 ? [toStr(flattenedChildren)] : []} | ||
children: children.flat(Infinity).filter(c => c != null)} | ||
}, { get: (tag, name) => tag.bind(null, name) }) | ||
const add = (dom, ...children) => { | ||
children = children.flat(Infinity).filter(c => c != null) | ||
if (children.length > 0) dom.childrenStrs.push(toStr(children)) | ||
dom.children.push(...children.flat(Infinity).filter(c => c != null)) | ||
return dom | ||
@@ -85,3 +87,7 @@ } | ||
val, oldVal: val, derive: f => state(f()), | ||
html: (...args) => "<!DOCTYPE html>" + tags.html(...args).render() | ||
html: (...args) => { | ||
const buf = ["<!DOCTYPE html>"] | ||
tags.html(...args).renderToBuf(buf) | ||
return buf.join("") | ||
} | ||
} |
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
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
339
28134
1