MCPcopy
hub / github.com/MithrilJS/mithril.js / hyperscript

Function hyperscript

mithril.js:82–105  ·  view source on GitHub ↗
(selector)

Source from the content-addressed store, hash-verified

80 return Vnode(state.tag, attrs.key, hasAttrs ? attrs : null, childList, text)
81}
82function hyperscript(selector) {
83 if (selector == null || typeof selector !== "string" && typeof selector !== "function" && typeof selector.view !== "function") {
84 throw Error("The selector must be either a string or a component.");
85 }
86 var attrs = arguments[1], start = 2, children
87 if (attrs == null) {
88 attrs = {}
89 } else if (typeof attrs !== "object" || attrs.tag != null || Array.isArray(attrs)) {
90 attrs = {}
91 start = 1
92 }
93 if (arguments.length === start + 1) {
94 children = arguments[start]
95 if (!Array.isArray(children)) children = [children]
96 } else {
97 children = []
98 while (start < arguments.length) children.push(arguments[start++])
99 }
100 if (typeof selector === "string") {
101 return execSelector(selectorCache[selector] || compileSelector(selector), attrs, Vnode.normalizeChildren(children))
102 } else {
103 return Vnode(selector, attrs.key, attrs, children)
104 }
105}
106hyperscript.trust = function(html) {
107 if (html == null) html = ""
108 return Vnode("<", undefined, undefined, html, undefined, undefined)

Callers

nothing calls this directly

Calls 3

execSelectorFunction · 0.70
compileSelectorFunction · 0.70
VnodeFunction · 0.70

Tested by

no test coverage detected