Bundled output for commit a8409aabbd [skip ci]
This commit is contained in:
parent
a8409aabbd
commit
828a8bda98
2 changed files with 66 additions and 76 deletions
84
mithril.js
84
mithril.js
|
|
@ -206,42 +206,40 @@ function hyperscript(selector) {
|
|||
if (selector == null || typeof selector !== "string" && selector.view == null) {
|
||||
throw Error("The selector must be either a string or a component.");
|
||||
}
|
||||
if (typeof selector === "string") {
|
||||
if (selectorCache[selector] === undefined) {
|
||||
var match, tag, classes = [], attributes = {}
|
||||
while (match = selectorParser.exec(selector)) {
|
||||
var type = match[1], value = match[2]
|
||||
if (type === "" && value !== "") tag = value
|
||||
else if (type === "#") attributes.id = value
|
||||
else if (type === ".") classes.push(value)
|
||||
else if (match[3][0] === "[") {
|
||||
var attrValue = match[6]
|
||||
if (attrValue) attrValue = attrValue.replace(/\\(["'])/g, "$1").replace(/\\\\/g, "\\")
|
||||
attributes[match[4]] = attrValue || true
|
||||
if (typeof selector === "string" && selectorCache[selector] === undefined) {
|
||||
var match, tag, classes = [], attributes = {}
|
||||
while (match = selectorParser.exec(selector)) {
|
||||
var type = match[1], value = match[2]
|
||||
if (type === "" && value !== "") tag = value
|
||||
else if (type === "#") attributes.id = value
|
||||
else if (type === ".") classes.push(value)
|
||||
else if (match[3][0] === "[") {
|
||||
var attrValue = match[6]
|
||||
if (attrValue) attrValue = attrValue.replace(/\\(["'])/g, "$1").replace(/\\\\/g, "\\")
|
||||
attributes[match[4]] = attrValue || true
|
||||
}
|
||||
}
|
||||
if (classes.length > 0) attributes.className = classes.join(" ")
|
||||
selectorCache[selector] = function(attrs, children) {
|
||||
var hasAttrs = false, childList, text
|
||||
var className = attrs.className || attrs.class
|
||||
for (var key in attributes) attrs[key] = attributes[key]
|
||||
if (className !== undefined) {
|
||||
if (attrs.class !== undefined) {
|
||||
attrs.class = undefined
|
||||
attrs.className = className
|
||||
}
|
||||
if (attributes.className !== undefined) attrs.className = attributes.className + " " + className
|
||||
}
|
||||
for (var key in attrs) {
|
||||
if (key !== "key") {
|
||||
hasAttrs = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if (classes.length > 0) attributes.className = classes.join(" ")
|
||||
selectorCache[selector] = function(attrs, children) {
|
||||
var hasAttrs = false, childList, text
|
||||
var className = attrs.className || attrs.class
|
||||
for (var key in attributes) attrs[key] = attributes[key]
|
||||
if (className !== undefined) {
|
||||
if (attrs.class !== undefined) {
|
||||
attrs.class = undefined
|
||||
attrs.className = className
|
||||
}
|
||||
if (attributes.className !== undefined) attrs.className = attributes.className + " " + className
|
||||
}
|
||||
for (var key in attrs) {
|
||||
if (key !== "key") {
|
||||
hasAttrs = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if (children instanceof Array && children.length == 1 && children[0] != null && children[0].tag === "#") text = children[0].children
|
||||
else childList = children
|
||||
return Vnode(tag || "div", attrs.key, hasAttrs ? attrs : undefined, childList, text, undefined)
|
||||
}
|
||||
if (children instanceof Array && children.length == 1 && children[0] != null && children[0].tag === "#") text = children[0].children
|
||||
else childList = children
|
||||
return Vnode(tag || "div", attrs.key, hasAttrs ? attrs : undefined, childList, text, undefined)
|
||||
}
|
||||
}
|
||||
var attrs, children, childrenIndex
|
||||
|
|
@ -342,7 +340,9 @@ var renderService = function($window) {
|
|||
return element
|
||||
}
|
||||
function createComponent(vnode, hooks, ns) {
|
||||
vnode.state = copy(vnode.tag)
|
||||
// For object literals since `Vnode()` always sets the `state` field.
|
||||
if (!vnode.state) vnode.state = {}
|
||||
assign(vnode.state, vnode.tag)
|
||||
initLifecycle(vnode.tag, vnode, hooks)
|
||||
vnode.instance = Vnode.normalize(vnode.tag.view.call(vnode.state, vnode))
|
||||
if (vnode.instance != null) {
|
||||
|
|
@ -741,18 +741,8 @@ var renderService = function($window) {
|
|||
}
|
||||
return false
|
||||
}
|
||||
function copy(data) {
|
||||
if (data instanceof Array) {
|
||||
var output = []
|
||||
for (var i = 0; i < data.length; i++) output[i] = data[i]
|
||||
return output
|
||||
}
|
||||
else if (typeof data === "object") {
|
||||
var output = {}
|
||||
for (var i in data) output[i] = data[i]
|
||||
return output
|
||||
}
|
||||
return data
|
||||
function assign(target, source) {
|
||||
Object.keys(source).forEach(function(k){target[k] = source[k]})
|
||||
}
|
||||
function render(dom, vnodes) {
|
||||
var hooks = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue