mirror of
https://git.hmsn.ink/kospo/helptalk/api.git
synced 2026-03-20 10:53:29 +09:00
first
This commit is contained in:
35
sample/dev/talk/bundle/mithril-2.2.2/render/vnode.js
Normal file
35
sample/dev/talk/bundle/mithril-2.2.2/render/vnode.js
Normal file
@@ -0,0 +1,35 @@
|
||||
"use strict"
|
||||
|
||||
function Vnode(tag, key, attrs, children, text, dom) {
|
||||
return {tag: tag, key: key, attrs: attrs, children: children, text: text, dom: dom, domSize: undefined, state: undefined, events: undefined, instance: undefined}
|
||||
}
|
||||
Vnode.normalize = function(node) {
|
||||
if (Array.isArray(node)) return Vnode("[", undefined, undefined, Vnode.normalizeChildren(node), undefined, undefined)
|
||||
if (node == null || typeof node === "boolean") return null
|
||||
if (typeof node === "object") return node
|
||||
return Vnode("#", undefined, undefined, String(node), undefined, undefined)
|
||||
}
|
||||
Vnode.normalizeChildren = function(input) {
|
||||
var children = []
|
||||
if (input.length) {
|
||||
var isKeyed = input[0] != null && input[0].key != null
|
||||
// Note: this is a *very* perf-sensitive check.
|
||||
// Fun fact: merging the loop like this is somehow faster than splitting
|
||||
// it, noticeably so.
|
||||
for (var i = 1; i < input.length; i++) {
|
||||
if ((input[i] != null && input[i].key != null) !== isKeyed) {
|
||||
throw new TypeError(
|
||||
isKeyed && (input[i] != null || typeof input[i] === "boolean")
|
||||
? "In fragments, vnodes must either all have keys or none have keys. You may wish to consider using an explicit keyed empty fragment, m.fragment({key: ...}), instead of a hole."
|
||||
: "In fragments, vnodes must either all have keys or none have keys."
|
||||
)
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < input.length; i++) {
|
||||
children[i] = Vnode.normalize(input[i])
|
||||
}
|
||||
}
|
||||
return children
|
||||
}
|
||||
|
||||
module.exports = Vnode
|
||||
Reference in New Issue
Block a user