-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmini-van-0.2.2.js
More file actions
27 lines (21 loc) · 912 Bytes
/
mini-van-0.2.2.js
File metadata and controls
27 lines (21 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/// <reference types="./mini-van.d.ts" />
// This file consistently uses `let` keyword instead of `const` for reducing the bundle size.
// Aliasing some builtin symbols to reduce the bundle size.
let Obj = Object
let vanWithDoc = doc => {
let toDom = v => v.nodeType ? v : doc.createTextNode(v)
let _result = {
add: (dom, ...children) => children.flat(Infinity).forEach(child => dom.appendChild(
toDom(child))),
tags: new Proxy((name, ...args) => {
let [props, ...children] = args[0]?.constructor === Obj ? args : [{}, ...args]
let dom = doc.createElement(name)
Obj.entries(props).forEach(([k, v]) =>
dom[k] !== undefined ? dom[k] = v : dom.setAttribute(k, v))
_result.add(dom, ...children)
return dom
}, {get: (tag, name) => tag.bind(null, name)})
}
return _result
}
export default {"vanWithDoc": vanWithDoc, ...vanWithDoc(window.document)}