Fixed bundle
This commit is contained in:
parent
16c892037b
commit
58cc89dc6a
1 changed files with 94 additions and 94 deletions
188
mithril.js
188
mithril.js
|
|
@ -1,48 +1,48 @@
|
||||||
new function() {
|
new function() {
|
||||||
"use strict"
|
"use strict"
|
||||||
var guid = 0, noop = function() {}, HALT = {}
|
var guid = 0, noop = function() {}, HALT = {}
|
||||||
function createStream1() {
|
function createStream() {
|
||||||
function stream() {
|
function stream() {
|
||||||
if (arguments.length > 0) updateStream1(stream, arguments[0], undefined)
|
if (arguments.length > 0) updateStream(stream, arguments[0], undefined)
|
||||||
return stream._state.value
|
return stream._state.value
|
||||||
}
|
}
|
||||||
initStream1(stream, arguments)
|
initStream(stream, arguments)
|
||||||
if (arguments.length > 0) updateStream1(stream, arguments[0], undefined)
|
if (arguments.length > 0) updateStream(stream, arguments[0], undefined)
|
||||||
return stream
|
return stream
|
||||||
}
|
}
|
||||||
function initStream1(stream, args) {
|
function initStream(stream, args) {
|
||||||
stream.constructor = createStream1
|
stream.constructor = createStream
|
||||||
stream._state = {id: guid++, value: undefined, error: undefined, state: 0, derive: undefined, recover: undefined, deps: {}, parents: [], errorStream1: undefined, endStream1: undefined}
|
stream._state = {id: guid++, value: undefined, error: undefined, state: 0, derive: undefined, recover: undefined, deps: {}, parents: [], errorStream: undefined, endStream: undefined}
|
||||||
stream.map = map, stream.ap = ap, stream.of = createStream1
|
stream.map = map, stream.ap = ap, stream.of = createStream
|
||||||
stream.valueOf = valueOf, stream.toJSON = toJSON, stream.toString = valueOf
|
stream.valueOf = valueOf, stream.toJSON = toJSON, stream.toString = valueOf
|
||||||
stream.run = run, stream.catch = doCatch
|
stream.run = run, stream.catch = doCatch
|
||||||
Object.defineProperties(stream, {
|
Object.defineProperties(stream, {
|
||||||
error: {get: function() {
|
error: {get: function() {
|
||||||
if (!stream._state.errorStream1) {
|
if (!stream._state.errorStream) {
|
||||||
var errorStream1 = function() {
|
var errorStream = function() {
|
||||||
if (arguments.length > 0) updateStream1(stream, undefined, arguments[0])
|
if (arguments.length > 0) updateStream(stream, undefined, arguments[0])
|
||||||
return stream._state.error
|
return stream._state.error
|
||||||
}
|
}
|
||||||
initStream1(errorStream1, [])
|
initStream(errorStream, [])
|
||||||
initDependency(errorStream1, [stream], noop, noop)
|
initDependency(errorStream, [stream], noop, noop)
|
||||||
stream._state.errorStream1 = errorStream1
|
stream._state.errorStream = errorStream
|
||||||
}
|
}
|
||||||
return stream._state.errorStream1
|
return stream._state.errorStream
|
||||||
}},
|
}},
|
||||||
end: {get: function() {
|
end: {get: function() {
|
||||||
if (!stream._state.endStream1) {
|
if (!stream._state.endStream) {
|
||||||
var endStream1 = createStream1()
|
var endStream = createStream()
|
||||||
endStream1.map(function(value) {
|
endStream.map(function(value) {
|
||||||
if (value === true) unregisterStream1(stream), unregisterStream1(endStream1)
|
if (value === true) unregisterStream(stream), unregisterStream(endStream)
|
||||||
return value
|
return value
|
||||||
})
|
})
|
||||||
stream._state.endStream1 = endStream1
|
stream._state.endStream = endStream
|
||||||
}
|
}
|
||||||
return stream._state.endStream1
|
return stream._state.endStream
|
||||||
}}
|
}}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
function updateStream1(stream, value, error) {
|
function updateStream(stream, value, error) {
|
||||||
updateState(stream, value, error)
|
updateState(stream, value, error)
|
||||||
for (var id in stream._state.deps) updateDependency(stream._state.deps[id], false)
|
for (var id in stream._state.deps) updateDependency(stream._state.deps[id], false)
|
||||||
finalize(stream)
|
finalize(stream)
|
||||||
|
|
@ -87,7 +87,7 @@ function updateDependency(stream, mustSync) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function unwrapError(value, error) {
|
function unwrapError(value, error) {
|
||||||
if (value != null && value.constructor === createStream1) {
|
if (value != null && value.constructor === createStream) {
|
||||||
if (value._state.error !== undefined) error = value._state.error
|
if (value._state.error !== undefined) error = value._state.error
|
||||||
else error = unwrapError(value._state.value, value._state.error)
|
else error = unwrapError(value._state.value, value._state.error)
|
||||||
}
|
}
|
||||||
|
|
@ -105,26 +105,26 @@ function reportUncaughtError(stream, e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function run(fn) {
|
function run(fn) {
|
||||||
var self = createStream1(), stream = this
|
var self = createStream(), stream = this
|
||||||
return initDependency(self, [stream], function() {
|
return initDependency(self, [stream], function() {
|
||||||
return absorb(self, fn(stream()))
|
return absorb(self, fn(stream()))
|
||||||
}, undefined)
|
}, undefined)
|
||||||
}
|
}
|
||||||
function doCatch(fn) {
|
function doCatch(fn) {
|
||||||
var self = createStream1(), stream = this
|
var self = createStream(), stream = this
|
||||||
var derive = function() {return stream._state.value}
|
var derive = function() {return stream._state.value}
|
||||||
var recover = function() {return absorb(self, fn(stream._state.error))}
|
var recover = function() {return absorb(self, fn(stream._state.error))}
|
||||||
return initDependency(self, [stream], derive, recover)
|
return initDependency(self, [stream], derive, recover)
|
||||||
}
|
}
|
||||||
function combine(fn, streams) {
|
function combine(fn, streams) {
|
||||||
return initDependency(createStream1(), streams, function() {
|
return initDependency(createStream(), streams, function() {
|
||||||
var failed = streams.filter(errored)
|
var failed = streams.filter(errored)
|
||||||
if (failed.length > 0) throw failed[0]._state.error
|
if (failed.length > 0) throw failed[0]._state.error
|
||||||
return fn.apply(this, streams.concat([streams.filter(changed)]))
|
return fn.apply(this, streams.concat([streams.filter(changed)]))
|
||||||
}, undefined)
|
}, undefined)
|
||||||
}
|
}
|
||||||
function absorb(stream, value) {
|
function absorb(stream, value) {
|
||||||
if (value != null && value.constructor === createStream1) {
|
if (value != null && value.constructor === createStream) {
|
||||||
value.error.map(stream.error)
|
value.error.map(stream.error)
|
||||||
value.map(stream)
|
value.map(stream)
|
||||||
if (value._state.state === 0) return HALT
|
if (value._state.state === 0) return HALT
|
||||||
|
|
@ -148,7 +148,7 @@ function registerDependency(stream, parents) {
|
||||||
registerDependency(stream, parents[i]._state.parents)
|
registerDependency(stream, parents[i]._state.parents)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function unregisterStream1(stream) {
|
function unregisterStream(stream) {
|
||||||
for (var i = 0; i < stream._state.parents.length; i++) {
|
for (var i = 0; i < stream._state.parents.length; i++) {
|
||||||
var parent = stream._state.parents[i]
|
var parent = stream._state.parents[i]
|
||||||
delete parent._state.deps[stream._state.id]
|
delete parent._state.deps[stream._state.id]
|
||||||
|
|
@ -170,7 +170,7 @@ function changed(stream) {return stream._state.changed}
|
||||||
function notEnded(stream) {return stream._state.state !== 2}
|
function notEnded(stream) {return stream._state.state !== 2}
|
||||||
function errored(stream) {return stream._state.error}
|
function errored(stream) {return stream._state.error}
|
||||||
function reject(e) {
|
function reject(e) {
|
||||||
var stream = createStream1()
|
var stream = createStream()
|
||||||
stream.error(e)
|
stream.error(e)
|
||||||
return stream
|
return stream
|
||||||
}
|
}
|
||||||
|
|
@ -179,9 +179,9 @@ function merge(streams) {
|
||||||
return streams.map(function (s) {return s()})
|
return streams.map(function (s) {return s()})
|
||||||
}, streams)
|
}, streams)
|
||||||
}
|
}
|
||||||
var Stream = {stream: createStream1, merge: merge, combine: combine, reject: reject, HALT: HALT}
|
var Stream = {stream: createStream, merge: merge, combine: combine, reject: reject, HALT: HALT}
|
||||||
function Vnode(tag, key, attrs, children, text, dom1) {
|
function Vnode(tag, key, attrs, children, text, dom) {
|
||||||
return {tag: tag, key: key, attrs: attrs, children: children, text: text, dom1: dom1, domSize: undefined, state: {}, events: undefined, instance: undefined}
|
return {tag: tag, key: key, attrs: attrs, children: children, text: text, dom: dom, domSize: undefined, state: {}, events: undefined, instance: undefined}
|
||||||
}
|
}
|
||||||
Vnode.normalize = function(node) {
|
Vnode.normalize = function(node) {
|
||||||
if (node instanceof Array) return Vnode("[", undefined, undefined, Vnode.normalizeChildren(node), undefined, undefined)
|
if (node instanceof Array) return Vnode("[", undefined, undefined, Vnode.normalizeChildren(node), undefined, undefined)
|
||||||
|
|
@ -280,14 +280,14 @@ var renderService = function($window) {
|
||||||
else return createComponent(vnode, hooks, ns)
|
else return createComponent(vnode, hooks, ns)
|
||||||
}
|
}
|
||||||
function createText(vnode) {
|
function createText(vnode) {
|
||||||
return vnode.dom2 = $doc.createTextNode(vnode.children)
|
return vnode.dom = $doc.createTextNode(vnode.children)
|
||||||
}
|
}
|
||||||
function createHTML(vnode) {
|
function createHTML(vnode) {
|
||||||
var match = vnode.children.match(/^\s*?<(\w+)/im2) || []
|
var match = vnode.children.match(/^\s*?<(\w+)/im) || []
|
||||||
var parent = {caption: "table", thead: "table", tbody: "table", tfoot: "table", tr: "tbody", th: "tr", td: "tr", colgroup: "table", col: "colgroup"}[match[1]] || "div"
|
var parent = {caption: "table", thead: "table", tbody: "table", tfoot: "table", tr: "tbody", th: "tr", td: "tr", colgroup: "table", col: "colgroup"}[match[1]] || "div"
|
||||||
var temp = $doc.createElement(parent)
|
var temp = $doc.createElement(parent)
|
||||||
temp.innerHTML = vnode.children
|
temp.innerHTML = vnode.children
|
||||||
vnode.dom2 = temp.firstChild
|
vnode.dom = temp.firstChild
|
||||||
vnode.domSize = temp.childNodes.length
|
vnode.domSize = temp.childNodes.length
|
||||||
var fragment = $doc.createDocumentFragment()
|
var fragment = $doc.createDocumentFragment()
|
||||||
var child
|
var child
|
||||||
|
|
@ -302,7 +302,7 @@ var renderService = function($window) {
|
||||||
var children = vnode.children
|
var children = vnode.children
|
||||||
createNodes(fragment, children, 0, children.length, hooks, null, ns)
|
createNodes(fragment, children, 0, children.length, hooks, null, ns)
|
||||||
}
|
}
|
||||||
vnode.dom2 = fragment.firstChild
|
vnode.dom = fragment.firstChild
|
||||||
vnode.domSize = fragment.childNodes.length
|
vnode.domSize = fragment.childNodes.length
|
||||||
return fragment
|
return fragment
|
||||||
}
|
}
|
||||||
|
|
@ -317,7 +317,7 @@ var renderService = function($window) {
|
||||||
var element = ns ?
|
var element = ns ?
|
||||||
is ? $doc.createElementNS(ns, tag, is) : $doc.createElementNS(ns, tag) :
|
is ? $doc.createElementNS(ns, tag, is) : $doc.createElementNS(ns, tag) :
|
||||||
is ? $doc.createElement(tag, is) : $doc.createElement(tag)
|
is ? $doc.createElement(tag, is) : $doc.createElement(tag)
|
||||||
vnode.dom2 = element
|
vnode.dom = element
|
||||||
if (attrs != null) {
|
if (attrs != null) {
|
||||||
setAttrs(vnode, attrs, ns)
|
setAttrs(vnode, attrs, ns)
|
||||||
}
|
}
|
||||||
|
|
@ -338,8 +338,8 @@ var renderService = function($window) {
|
||||||
vnode.instance = Vnode.normalize(vnode.tag.view.call(vnode.state, vnode))
|
vnode.instance = Vnode.normalize(vnode.tag.view.call(vnode.state, vnode))
|
||||||
if (vnode.instance != null) {
|
if (vnode.instance != null) {
|
||||||
var element = createNode(vnode.instance, hooks, ns)
|
var element = createNode(vnode.instance, hooks, ns)
|
||||||
vnode.dom2 = vnode.instance.dom2
|
vnode.dom = vnode.instance.dom
|
||||||
vnode.domSize = vnode.dom2 != null ? vnode.instance.domSize : 0
|
vnode.domSize = vnode.dom != null ? vnode.instance.domSize : 0
|
||||||
return element
|
return element
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -392,7 +392,7 @@ var renderService = function($window) {
|
||||||
else if (o != null && v != null && o.key === v.key) {
|
else if (o != null && v != null && o.key === v.key) {
|
||||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
|
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
|
||||||
if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
|
if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
|
||||||
if (o.dom2 != null) nextSibling = o.dom2
|
if (o.dom != null) nextSibling = o.dom
|
||||||
oldEnd--, end--
|
oldEnd--, end--
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -404,12 +404,12 @@ var renderService = function($window) {
|
||||||
updateNode(parent, movable, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
|
updateNode(parent, movable, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
|
||||||
insertNode(parent, toFragment(movable), nextSibling)
|
insertNode(parent, toFragment(movable), nextSibling)
|
||||||
old[oldIndex].skip = true
|
old[oldIndex].skip = true
|
||||||
if (movable.dom2 != null) nextSibling = movable.dom2
|
if (movable.dom != null) nextSibling = movable.dom
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var dom2 = createNode(v, hooks, undefined)
|
var dom = createNode(v, hooks, undefined)
|
||||||
insertNode(parent, dom2, nextSibling)
|
insertNode(parent, dom, nextSibling)
|
||||||
nextSibling = dom2
|
nextSibling = dom
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end--
|
end--
|
||||||
|
|
@ -447,26 +447,26 @@ var renderService = function($window) {
|
||||||
}
|
}
|
||||||
function updateText(old, vnode) {
|
function updateText(old, vnode) {
|
||||||
if (old.children.toString() !== vnode.children.toString()) {
|
if (old.children.toString() !== vnode.children.toString()) {
|
||||||
old.dom2.nodeValue = vnode.children
|
old.dom.nodeValue = vnode.children
|
||||||
}
|
}
|
||||||
vnode.dom2 = old.dom2
|
vnode.dom = old.dom
|
||||||
}
|
}
|
||||||
function updateHTML(parent, old, vnode, nextSibling) {
|
function updateHTML(parent, old, vnode, nextSibling) {
|
||||||
if (old.children !== vnode.children) {
|
if (old.children !== vnode.children) {
|
||||||
toFragment(old)
|
toFragment(old)
|
||||||
insertNode(parent, createHTML(vnode), nextSibling)
|
insertNode(parent, createHTML(vnode), nextSibling)
|
||||||
}
|
}
|
||||||
else vnode.dom2 = old.dom2
|
else vnode.dom = old.dom
|
||||||
}
|
}
|
||||||
function updateFragment(parent, old, vnode, hooks, nextSibling, ns) {
|
function updateFragment(parent, old, vnode, hooks, nextSibling, ns) {
|
||||||
updateNodes(parent, old.children, vnode.children, hooks, nextSibling, ns)
|
updateNodes(parent, old.children, vnode.children, hooks, nextSibling, ns)
|
||||||
var domSize = 0, children = vnode.children
|
var domSize = 0, children = vnode.children
|
||||||
vnode.dom2 = null
|
vnode.dom = null
|
||||||
if (children != null) {
|
if (children != null) {
|
||||||
for (var i = 0; i < children.length; i++) {
|
for (var i = 0; i < children.length; i++) {
|
||||||
var child = children[i]
|
var child = children[i]
|
||||||
if (child != null && child.dom2 != null) {
|
if (child != null && child.dom != null) {
|
||||||
if (vnode.dom2 == null) vnode.dom2 = child.dom2
|
if (vnode.dom == null) vnode.dom = child.dom
|
||||||
domSize += child.domSize || 1
|
domSize += child.domSize || 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -474,7 +474,7 @@ var renderService = function($window) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function updateElement(old, vnode, hooks, ns) {
|
function updateElement(old, vnode, hooks, ns) {
|
||||||
var element = vnode.dom2 = old.dom2
|
var element = vnode.dom = old.dom
|
||||||
switch (vnode.tag) {
|
switch (vnode.tag) {
|
||||||
case "svg": ns = "http://www.w3.org/2000/svg"; break
|
case "svg": ns = "http://www.w3.org/2000/svg"; break
|
||||||
case "math": ns = "http://www.w3.org/1998/Math/MathML"; break
|
case "math": ns = "http://www.w3.org/1998/Math/MathML"; break
|
||||||
|
|
@ -485,10 +485,10 @@ var renderService = function($window) {
|
||||||
}
|
}
|
||||||
updateAttrs(vnode, old.attrs, vnode.attrs, ns)
|
updateAttrs(vnode, old.attrs, vnode.attrs, ns)
|
||||||
if (old.text != null && vnode.text != null && vnode.text !== "") {
|
if (old.text != null && vnode.text != null && vnode.text !== "") {
|
||||||
if (old.text.toString() !== vnode.text.toString()) old.dom2.firstChild.nodeValue = vnode.text
|
if (old.text.toString() !== vnode.text.toString()) old.dom.firstChild.nodeValue = vnode.text
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (old.text != null) old.children = [Vnode("#", undefined, undefined, old.text, undefined, old.dom2.firstChild)]
|
if (old.text != null) old.children = [Vnode("#", undefined, undefined, old.text, undefined, old.dom.firstChild)]
|
||||||
if (vnode.text != null) vnode.children = [Vnode("#", undefined, undefined, vnode.text, undefined, undefined)]
|
if (vnode.text != null) vnode.children = [Vnode("#", undefined, undefined, vnode.text, undefined, undefined)]
|
||||||
updateNodes(element, old.children, vnode.children, hooks, null, ns)
|
updateNodes(element, old.children, vnode.children, hooks, null, ns)
|
||||||
}
|
}
|
||||||
|
|
@ -499,16 +499,16 @@ var renderService = function($window) {
|
||||||
if (vnode.instance != null) {
|
if (vnode.instance != null) {
|
||||||
if (old.instance == null) insertNode(parent, createNode(vnode.instance, hooks, ns), nextSibling)
|
if (old.instance == null) insertNode(parent, createNode(vnode.instance, hooks, ns), nextSibling)
|
||||||
else updateNode(parent, old.instance, vnode.instance, hooks, nextSibling, recycling, ns)
|
else updateNode(parent, old.instance, vnode.instance, hooks, nextSibling, recycling, ns)
|
||||||
vnode.dom2 = vnode.instance.dom2
|
vnode.dom = vnode.instance.dom
|
||||||
vnode.domSize = vnode.instance.domSize
|
vnode.domSize = vnode.instance.domSize
|
||||||
}
|
}
|
||||||
else if (old.instance != null) {
|
else if (old.instance != null) {
|
||||||
removeNode(parent, old.instance, null, false)
|
removeNode(parent, old.instance, null, false)
|
||||||
vnode.dom2 = undefined
|
vnode.dom = undefined
|
||||||
vnode.domSize = 0
|
vnode.domSize = 0
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
vnode.dom2 = old.dom2
|
vnode.dom = old.dom
|
||||||
vnode.domSize = old.domSize
|
vnode.domSize = old.domSize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -536,26 +536,26 @@ var renderService = function($window) {
|
||||||
}
|
}
|
||||||
function toFragment(vnode) {
|
function toFragment(vnode) {
|
||||||
var count = vnode.domSize
|
var count = vnode.domSize
|
||||||
if (count != null || vnode.dom2 == null) {
|
if (count != null || vnode.dom == null) {
|
||||||
var fragment = $doc.createDocumentFragment()
|
var fragment = $doc.createDocumentFragment()
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
var dom2 = vnode.dom2
|
var dom = vnode.dom
|
||||||
while (--count) fragment.appendChild(dom2.nextSibling)
|
while (--count) fragment.appendChild(dom.nextSibling)
|
||||||
fragment.insertBefore(dom2, fragment.firstChild)
|
fragment.insertBefore(dom, fragment.firstChild)
|
||||||
}
|
}
|
||||||
return fragment
|
return fragment
|
||||||
}
|
}
|
||||||
else return vnode.dom2
|
else return vnode.dom
|
||||||
}
|
}
|
||||||
function getNextSibling(vnodes, i, nextSibling) {
|
function getNextSibling(vnodes, i, nextSibling) {
|
||||||
for (; i < vnodes.length; i++) {
|
for (; i < vnodes.length; i++) {
|
||||||
if (vnodes[i] != null && vnodes[i].dom2 != null) return vnodes[i].dom2
|
if (vnodes[i] != null && vnodes[i].dom != null) return vnodes[i].dom
|
||||||
}
|
}
|
||||||
return nextSibling
|
return nextSibling
|
||||||
}
|
}
|
||||||
function insertNode(parent, dom2, nextSibling) {
|
function insertNode(parent, dom, nextSibling) {
|
||||||
if (nextSibling && nextSibling.parentNode) parent.insertBefore(dom2, nextSibling)
|
if (nextSibling && nextSibling.parentNode) parent.insertBefore(dom, nextSibling)
|
||||||
else parent.appendChild(dom2)
|
else parent.appendChild(dom)
|
||||||
}
|
}
|
||||||
//remove
|
//remove
|
||||||
function removeNodes(parent, vnodes, start, end, context) {
|
function removeNodes(parent, vnodes, start, end, context) {
|
||||||
|
|
@ -584,16 +584,16 @@ var renderService = function($window) {
|
||||||
if (expected > 0) return
|
if (expected > 0) return
|
||||||
}
|
}
|
||||||
onremove(vnode)
|
onremove(vnode)
|
||||||
if (vnode.dom2) {
|
if (vnode.dom) {
|
||||||
var count = vnode.domSize || 1
|
var count = vnode.domSize || 1
|
||||||
if (count > 1) {
|
if (count > 1) {
|
||||||
var dom2 = vnode.dom2
|
var dom = vnode.dom
|
||||||
while (--count) {
|
while (--count) {
|
||||||
parent.removeChild(dom2.nextSibling)
|
parent.removeChild(dom.nextSibling)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (vnode.dom2.parentNode != null) parent.removeChild(vnode.dom2)
|
if (vnode.dom.parentNode != null) parent.removeChild(vnode.dom)
|
||||||
if (context != null && vnode.domSize == null && !hasIntegrationMethods(vnode.attrs) && typeof vnode.tag === "string") { //TODO test custom2 elements
|
if (context != null && vnode.domSize == null && !hasIntegrationMethods(vnode.attrs) && typeof vnode.tag === "string") { //TODO test custom elements
|
||||||
if (!context.pool) context.pool = [vnode]
|
if (!context.pool) context.pool = [vnode]
|
||||||
else context.pool.push(vnode)
|
else context.pool.push(vnode)
|
||||||
}
|
}
|
||||||
|
|
@ -620,7 +620,7 @@ var renderService = function($window) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function setAttr(vnode, key, old, value, ns) {
|
function setAttr(vnode, key, old, value, ns) {
|
||||||
var element = vnode.dom2
|
var element = vnode.dom
|
||||||
if (key === "key" || (old === value && !isFormAttribute(vnode, key)) && typeof value !== "object" || typeof value === "undefined" || isLifecycleMethod(key)) return
|
if (key === "key" || (old === value && !isFormAttribute(vnode, key)) && typeof value !== "object" || typeof value === "undefined" || isLifecycleMethod(key)) return
|
||||||
var nsLastIndex = key.indexOf(":")
|
var nsLastIndex = key.indexOf(":")
|
||||||
if (nsLastIndex > -1 && key.substr(0, nsLastIndex) === "xlink") {
|
if (nsLastIndex > -1 && key.substr(0, nsLastIndex) === "xlink") {
|
||||||
|
|
@ -630,7 +630,7 @@ var renderService = function($window) {
|
||||||
else if (key === "style") updateStyle(element, old, value)
|
else if (key === "style") updateStyle(element, old, value)
|
||||||
else if (key in element && !isAttribute(key) && ns === undefined) {
|
else if (key in element && !isAttribute(key) && ns === undefined) {
|
||||||
//setting input[value] to same value by typing on focused element moves cursor to end in Chrome
|
//setting input[value] to same value by typing on focused element moves cursor to end in Chrome
|
||||||
if (vnode.tag === "input" && key === "value" && vnode.dom2.value === value && vnode.dom2 === $doc.activeElement) return
|
if (vnode.tag === "input" && key === "value" && vnode.dom.value === value && vnode.dom === $doc.activeElement) return
|
||||||
element[key] = value
|
element[key] = value
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -657,13 +657,13 @@ var renderService = function($window) {
|
||||||
if (old != null) {
|
if (old != null) {
|
||||||
for (var key in old) {
|
for (var key in old) {
|
||||||
if (attrs == null || !(key in attrs)) {
|
if (attrs == null || !(key in attrs)) {
|
||||||
if (key !== "key") vnode.dom2.removeAttribute(key)
|
if (key !== "key") vnode.dom.removeAttribute(key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function isFormAttribute(vnode, attr) {
|
function isFormAttribute(vnode, attr) {
|
||||||
return attr === "value" || attr === "checked" || attr === "selectedIndex" || attr === "selected" && vnode.dom2 === $doc.activeElement
|
return attr === "value" || attr === "checked" || attr === "selectedIndex" || attr === "selected" && vnode.dom === $doc.activeElement
|
||||||
}
|
}
|
||||||
function isLifecycleMethod(attr) {
|
function isLifecycleMethod(attr) {
|
||||||
return attr === "oninit" || attr === "oncreate" || attr === "onupdate" || attr === "onremove" || attr === "onbeforeremove" || attr === "onbeforeupdate"
|
return attr === "oninit" || attr === "oncreate" || attr === "onupdate" || attr === "onremove" || attr === "onbeforeremove" || attr === "onbeforeupdate"
|
||||||
|
|
@ -693,7 +693,7 @@ var renderService = function($window) {
|
||||||
}
|
}
|
||||||
//event
|
//event
|
||||||
function updateEvent(vnode, key, value) {
|
function updateEvent(vnode, key, value) {
|
||||||
var element = vnode.dom2
|
var element = vnode.dom
|
||||||
var callback = function(e) {
|
var callback = function(e) {
|
||||||
var result = value.call(element, e)
|
var result = value.call(element, e)
|
||||||
if (typeof onevent === "function") onevent.call(element, e)
|
if (typeof onevent === "function") onevent.call(element, e)
|
||||||
|
|
@ -722,7 +722,7 @@ var renderService = function($window) {
|
||||||
if (vnode.attrs != null && typeof vnode.attrs.onbeforeupdate === "function") forceVnodeUpdate = vnode.attrs.onbeforeupdate.call(vnode.state, vnode, old)
|
if (vnode.attrs != null && typeof vnode.attrs.onbeforeupdate === "function") forceVnodeUpdate = vnode.attrs.onbeforeupdate.call(vnode.state, vnode, old)
|
||||||
if (typeof vnode.tag !== "string" && typeof vnode.tag.onbeforeupdate === "function") forceComponentUpdate = vnode.tag.onbeforeupdate.call(vnode.state, vnode, old)
|
if (typeof vnode.tag !== "string" && typeof vnode.tag.onbeforeupdate === "function") forceComponentUpdate = vnode.tag.onbeforeupdate.call(vnode.state, vnode, old)
|
||||||
if (!(forceVnodeUpdate === undefined && forceComponentUpdate === undefined) && !forceVnodeUpdate && !forceComponentUpdate) {
|
if (!(forceVnodeUpdate === undefined && forceComponentUpdate === undefined) && !forceVnodeUpdate && !forceComponentUpdate) {
|
||||||
vnode.dom2 = old.dom2
|
vnode.dom = old.dom
|
||||||
vnode.domSize = old.domSize
|
vnode.domSize = old.domSize
|
||||||
vnode.instance = old.instance
|
vnode.instance = old.instance
|
||||||
return true
|
return true
|
||||||
|
|
@ -742,13 +742,13 @@ var renderService = function($window) {
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
function render(dom2, vnodes) {
|
function render(dom, vnodes) {
|
||||||
var hooks = []
|
var hooks = []
|
||||||
var active = $doc.activeElement
|
var active = $doc.activeElement
|
||||||
if (dom2.vnodes == null) dom2.vnodes = []
|
if (dom.vnodes == null) dom.vnodes = []
|
||||||
if (!(vnodes instanceof Array)) vnodes = [vnodes]
|
if (!(vnodes instanceof Array)) vnodes = [vnodes]
|
||||||
updateNodes(dom2, dom2.vnodes, Vnode.normalizeChildren(vnodes), hooks, null, undefined)
|
updateNodes(dom, dom.vnodes, Vnode.normalizeChildren(vnodes), hooks, null, undefined)
|
||||||
dom2.vnodes = vnodes
|
dom.vnodes = vnodes
|
||||||
for (var i = 0; i < hooks.length; i++) hooks[i]()
|
for (var i = 0; i < hooks.length; i++) hooks[i]()
|
||||||
if ($doc.activeElement !== active) active.focus()
|
if ($doc.activeElement !== active) active.focus()
|
||||||
}
|
}
|
||||||
|
|
@ -781,8 +781,8 @@ var requestService = function($window) {
|
||||||
function setCompletionCallback(callback) {oncompletion = callback}
|
function setCompletionCallback(callback) {oncompletion = callback}
|
||||||
|
|
||||||
function xhr(args) {
|
function xhr(args) {
|
||||||
var stream3 = Stream.stream3()
|
var stream = Stream.stream()
|
||||||
if (args.initialValue !== undefined) stream3(args.initialValue)
|
if (args.initialValue !== undefined) stream(args.initialValue)
|
||||||
|
|
||||||
var useBody = typeof args.useBody === "boolean" ? args.useBody : args.method !== "GET" && args.method !== "TRACE"
|
var useBody = typeof args.useBody === "boolean" ? args.useBody : args.method !== "GET" && args.method !== "TRACE"
|
||||||
|
|
||||||
|
|
@ -820,16 +820,16 @@ var requestService = function($window) {
|
||||||
else response = new args.type(response)
|
else response = new args.type(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
stream3(response)
|
stream(response)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var error = new Error(xhr.responseText)
|
var error = new Error(xhr.responseText)
|
||||||
for (var key in response) error[key] = response[key]
|
for (var key in response) error[key] = response[key]
|
||||||
stream3.error(error)
|
stream.error(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
stream3.error(e)
|
stream.error(e)
|
||||||
}
|
}
|
||||||
if (typeof oncompletion === "function") oncompletion()
|
if (typeof oncompletion === "function") oncompletion()
|
||||||
}
|
}
|
||||||
|
|
@ -838,22 +838,22 @@ var requestService = function($window) {
|
||||||
if (useBody) xhr.send(args.data)
|
if (useBody) xhr.send(args.data)
|
||||||
else xhr.send()
|
else xhr.send()
|
||||||
|
|
||||||
return stream3
|
return stream
|
||||||
}
|
}
|
||||||
function jsonp(args) {
|
function jsonp(args) {
|
||||||
var stream3 = Stream.stream3()
|
var stream = Stream.stream()
|
||||||
|
|
||||||
var callbackName = args.callbackName || "_mithril_" + Math.round(Math.random3() * 1e16) + "_" + callbackCount++
|
var callbackName = args.callbackName || "_mithril_" + Math.round(Math.random() * 1e16) + "_" + callbackCount++
|
||||||
var script = $window.document.createElement("script")
|
var script = $window.document.createElement("script")
|
||||||
$window[callbackName] = function(data) {
|
$window[callbackName] = function(data) {
|
||||||
script.parentNode.removeChild(script)
|
script.parentNode.removeChild(script)
|
||||||
stream3(data)
|
stream(data)
|
||||||
if (typeof oncompletion === "function") oncompletion()
|
if (typeof oncompletion === "function") oncompletion()
|
||||||
delete $window[callbackName]
|
delete $window[callbackName]
|
||||||
}
|
}
|
||||||
script.onerror = function() {
|
script.onerror = function() {
|
||||||
script.parentNode.removeChild(script)
|
script.parentNode.removeChild(script)
|
||||||
stream3.error(new Error("JSONP request failed"))
|
stream.error(new Error("JSONP request failed"))
|
||||||
if (typeof oncompletion === "function") oncompletion()
|
if (typeof oncompletion === "function") oncompletion()
|
||||||
delete $window[callbackName]
|
delete $window[callbackName]
|
||||||
}
|
}
|
||||||
|
|
@ -862,7 +862,7 @@ var requestService = function($window) {
|
||||||
args.data[args.callbackKey || "callback"] = callbackName
|
args.data[args.callbackKey || "callback"] = callbackName
|
||||||
script.src = assemble(args.url, args.data)
|
script.src = assemble(args.url, args.data)
|
||||||
$window.document.documentElement.appendChild(script)
|
$window.document.documentElement.appendChild(script)
|
||||||
return stream3
|
return stream
|
||||||
}
|
}
|
||||||
function interpolate(url, data) {
|
function interpolate(url, data) {
|
||||||
if (data == null) return url
|
if (data == null) return url
|
||||||
|
|
@ -949,7 +949,7 @@ var coreRouter = function($window) {
|
||||||
var prefix = "#!"
|
var prefix = "#!"
|
||||||
function setPrefix(value) {prefix = value}
|
function setPrefix(value) {prefix = value}
|
||||||
function normalize(fragment) {
|
function normalize(fragment) {
|
||||||
var data = $window.location[fragment].replace(/(?:%[a-f89][a-f0-9])+/gim4, decodeURIComponent)
|
var data = $window.location[fragment].replace(/(?:%[a-f89][a-f0-9])+/gim, decodeURIComponent)
|
||||||
if (fragment === "pathname" && data[0] !== "/") data = "/" + data
|
if (fragment === "pathname" && data[0] !== "/") data = "/" + data
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
@ -1027,8 +1027,8 @@ var coreRouter = function($window) {
|
||||||
return resolveRoute
|
return resolveRoute
|
||||||
}
|
}
|
||||||
function link(vnode) {
|
function link(vnode) {
|
||||||
vnode.dom4.setAttribute("href", prefix + vnode.attrs.href)
|
vnode.dom.setAttribute("href", prefix + vnode.attrs.href)
|
||||||
vnode.dom4.onclick = function(e) {
|
vnode.dom.onclick = function(e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.redraw = false
|
e.redraw = false
|
||||||
setPath(vnode.attrs.href, undefined, undefined)
|
setPath(vnode.attrs.href, undefined, undefined)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue