-
Notifications
You must be signed in to change notification settings - Fork 4
/
link.js
37 lines (33 loc) · 1.06 KB
/
link.js
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
28
29
30
31
32
33
34
35
36
37
/**
* Use this to easily link to an identity key. Keys are always converted to
* properties, so `null`/`undefined` are equivalent to `"null"` and
* `"undefined"` respectively.
*
* This is just a preview of something I'm looking to add in my redesign.
*/
;(function () {
"use strict"
var Vnode
function link(key, first) {
if (typeof key !== "symbol") key = "" + key
var children = first
if (!Array.isArray(children)) {
children = []
for (var i = 1; i < arguments.length; i++) {
children.push(arguments[i])
}
}
return Vnode("[", null, null, [
Vnode("[", key, null, Vnode.normalizeChildren(children))
])
}
if (typeof module === "object" && module && module.exports) {
Vnode = require("mithril/render/vnode")
module.exports = link
} else if (typeof m === "function") {
Vnode = m.vnode
(m.helpers || (m.helpers = {})).link = link
} else {
throw new Error("Mithril must be loaded first!")
}
})()