fix #1404
This commit is contained in:
parent
f7c187eec9
commit
713c25c9c0
24 changed files with 437 additions and 629 deletions
|
|
@ -34,6 +34,6 @@ There are over 4000 assertions in the test suite, and tests cover even difficult
|
|||
|
||||
## Modularity
|
||||
|
||||
Despite the huge improvements in performance and modularity, the new codebase is smaller than v0.2.x, currently clocking at <!-- size -->7.42 KB<!-- /size --> min+gzip
|
||||
Despite the huge improvements in performance and modularity, the new codebase is smaller than v0.2.x, currently clocking at <!-- size -->7.41 KB<!-- /size --> min+gzip
|
||||
|
||||
In addition, Mithril is now completely modular: you can import only the modules that you need and easily integrate 3rd party modules if you wish to use a different library for routing, ajax, and even rendering
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
"use strict"
|
||||
|
||||
var throttle = require("../api/throttle")
|
||||
|
||||
module.exports = function(root, renderer, pubsub, callback) {
|
||||
var run = throttle(callback)
|
||||
if (renderer != null) {
|
||||
renderer.setEventCallback(function(e) {
|
||||
if (e.redraw !== false) pubsub.publish()
|
||||
})
|
||||
}
|
||||
|
||||
if (pubsub != null) {
|
||||
if (root.redraw) pubsub.unsubscribe(root.redraw)
|
||||
pubsub.subscribe(run)
|
||||
}
|
||||
|
||||
return root.redraw = run
|
||||
}
|
||||
35
api/mount.js
35
api/mount.js
|
|
@ -1,23 +1,42 @@
|
|||
"use strict"
|
||||
|
||||
var Vnode = require("../render/vnode")
|
||||
var autoredraw = require("../api/autoredraw")
|
||||
|
||||
module.exports = function(renderer, pubsub) {
|
||||
module.exports = function(redrawService) {
|
||||
function throttle(callback) {
|
||||
//60fps translates to 16.6ms, round it down since setTimeout requires int
|
||||
var time = 16
|
||||
var last = 0, pending = null
|
||||
var timeout = typeof requestAnimationFrame === "function" ? requestAnimationFrame : setTimeout
|
||||
return function() {
|
||||
var now = Date.now()
|
||||
if (last === 0 || now - last >= time) {
|
||||
last = now
|
||||
callback()
|
||||
}
|
||||
else if (pending === null) {
|
||||
pending = timeout(function() {
|
||||
pending = null
|
||||
callback()
|
||||
last = Date.now()
|
||||
}, time - (now - last))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return function(root, component) {
|
||||
if (component === null) {
|
||||
renderer.render(root, [])
|
||||
pubsub.unsubscribe(root.redraw)
|
||||
delete root.redraw
|
||||
redrawService.render(root, [])
|
||||
redrawService.unsubscribe(root)
|
||||
return
|
||||
}
|
||||
|
||||
if (component.view == null) throw new Error("m.mount(element, component) expects a component, not a vnode")
|
||||
|
||||
var run = autoredraw(root, renderer, pubsub, function() {
|
||||
renderer.render(root, Vnode(component, undefined, undefined, undefined, undefined, undefined))
|
||||
var run = throttle(function() {
|
||||
redrawService.render(root, Vnode(component))
|
||||
})
|
||||
|
||||
redrawService.subscribe(root, run)
|
||||
run()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
"use strict"
|
||||
|
||||
module.exports = function() {
|
||||
var callbacks = []
|
||||
function unsubscribe(callback) {
|
||||
var index = callbacks.indexOf(callback)
|
||||
if (index > -1) callbacks.splice(index, 1)
|
||||
}
|
||||
function publish() {
|
||||
for (var i = 0; i < callbacks.length; i++) {
|
||||
callbacks[i].apply(this, arguments)
|
||||
}
|
||||
}
|
||||
return {subscribe: callbacks.push.bind(callbacks), unsubscribe: unsubscribe, publish: publish}
|
||||
}
|
||||
26
api/redraw.js
Normal file
26
api/redraw.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
"use strict"
|
||||
|
||||
var coreRenderer = require("../render/render")
|
||||
|
||||
module.exports = function($window) {
|
||||
var renderService = coreRenderer($window)
|
||||
renderService.setEventCallback(function(e) {
|
||||
if (e.redraw !== false) redraw()
|
||||
})
|
||||
|
||||
var callbacks = []
|
||||
function subscribe(key, callback) {
|
||||
unsubscribe(key)
|
||||
callbacks.push(key, callback)
|
||||
}
|
||||
function unsubscribe(key) {
|
||||
var index = callbacks.indexOf(key)
|
||||
if (index > -1) callbacks.splice(index, 2)
|
||||
}
|
||||
function redraw() {
|
||||
for (var i = 1; i < callbacks.length; i += 2) {
|
||||
callbacks[i]()
|
||||
}
|
||||
}
|
||||
return {subscribe: subscribe, unsubscribe: unsubscribe, redraw: redraw, render: renderService.render}
|
||||
}
|
||||
|
|
@ -3,55 +3,44 @@
|
|||
var Vnode = require("../render/vnode")
|
||||
var coreRouter = require("../router/router")
|
||||
|
||||
module.exports = function($window, mount) {
|
||||
var router = coreRouter($window)
|
||||
var currentResolve, currentComponent, currentRender, currentArgs, currentPath
|
||||
module.exports = function($window, redrawService) {
|
||||
var routeService = coreRouter($window)
|
||||
|
||||
var RouteComponent = {view: function() {
|
||||
return [currentRender(Vnode(currentComponent, null, currentArgs, undefined, undefined, undefined))]
|
||||
}}
|
||||
function defaultRender(vnode) {
|
||||
return vnode
|
||||
}
|
||||
var identity = function(v) {return v}
|
||||
var current = {render: identity, component: null, path: null, resolve: null}
|
||||
var route = function(root, defaultRoute, routes) {
|
||||
currentComponent = "div"
|
||||
currentRender = defaultRender
|
||||
currentArgs = null
|
||||
|
||||
mount(root, RouteComponent)
|
||||
|
||||
router.defineRoutes(routes, function(payload, args, path) {
|
||||
var isResolver = typeof payload.view !== "function"
|
||||
var render = defaultRender
|
||||
|
||||
var resolve = currentResolve = function (component) {
|
||||
if (resolve !== currentResolve) return
|
||||
currentResolve = null
|
||||
|
||||
currentComponent = component != null ? component : isResolver ? "div" : payload
|
||||
currentRender = render
|
||||
currentArgs = args
|
||||
currentPath = path
|
||||
|
||||
root.redraw(true)
|
||||
if (root == null) throw new Error("Ensure the DOM element that was passed to `m.route` is not undefined")
|
||||
var render = function(resolver, component, params, path) {
|
||||
current.render = resolver.render || identity
|
||||
current.component = component
|
||||
current.path = path
|
||||
current.resolve = null
|
||||
redrawService.render(root, current.render(Vnode(component, undefined, params)))
|
||||
}
|
||||
var onmatch = function() {
|
||||
resolve()
|
||||
var run = routeService.defineRoutes(routes, function(component, params, path, route, isRouteChange) {
|
||||
if (component.view) render({}, component, params, path)
|
||||
else {
|
||||
if (component.onmatch) {
|
||||
if (isRouteChange === false && current.path === path || current.resolve != null) render(current, current.component, params)
|
||||
else {
|
||||
current.resolve = function(resolved) {
|
||||
render(component, resolved, params, path)
|
||||
}
|
||||
if (isResolver) {
|
||||
if (typeof payload.render === "function") render = payload.render.bind(payload)
|
||||
if (typeof payload.onmatch === "function") onmatch = payload.onmatch
|
||||
component.onmatch(function(resolved) {
|
||||
if (current.path !== path && current.resolve != null) current.resolve(resolved)
|
||||
}, params, path)
|
||||
}
|
||||
}
|
||||
else render(component, "div", params, path)
|
||||
}
|
||||
|
||||
onmatch.call(payload, resolve, args, path)
|
||||
}, function() {
|
||||
router.setPath(defaultRoute, null, {replace: true})
|
||||
routeService.setPath(defaultRoute)
|
||||
})
|
||||
redrawService.subscribe(root, run)
|
||||
}
|
||||
route.link = router.link
|
||||
route.prefix = router.setPrefix
|
||||
route.set = router.setPath
|
||||
route.get = function() {return currentPath}
|
||||
|
||||
route.set = routeService.setPath
|
||||
route.get = function() {return current.path}
|
||||
route.prefix = routeService.setPrefix
|
||||
route.link = routeService.link
|
||||
return route
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
<script src="../../test-utils/xhrMock.js"></script>
|
||||
<script src="../../test-utils/browserMock.js"></script>
|
||||
|
||||
<script src="../../util/stream.js"></script>
|
||||
<script src="../../promise/promise.js"></script>
|
||||
<script src="../../render/vnode.js"></script>
|
||||
<script src="../../render/trust.js"></script>
|
||||
<script src="../../render/fragment.js"></script>
|
||||
|
|
@ -24,15 +24,11 @@
|
|||
<script src="../../querystring/parse.js"></script>
|
||||
<script src="../../request/request.js"></script>
|
||||
<script src="../../router/router.js"></script>
|
||||
<script src="../../api/throttle.js"></script>
|
||||
<script src="../../api/pubsub.js"></script>
|
||||
<script src="../../api/autoredraw.js"></script>
|
||||
<script src="../../api/redraw.js"></script>
|
||||
<script src="../../api/mount.js"></script>
|
||||
<script src="../../api/router.js"></script>
|
||||
|
||||
<script src="./test-throttle.js"></script>
|
||||
<script src="./test-pubsub.js"></script>
|
||||
<script src="./test-autoredraw.js"></script>
|
||||
<script src="./test-redraw.js"></script>
|
||||
<script src="./test-mount.js"></script>
|
||||
<script src="./test-router.js"></script>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,95 +0,0 @@
|
|||
"use strict"
|
||||
|
||||
var o = require("../../ospec/ospec")
|
||||
var domMock = require("../../test-utils/domMock")
|
||||
|
||||
var coreRenderer = require("../../render/render")
|
||||
var apiPubSub = require("../../api/pubsub")
|
||||
var autoredraw = require("../../api/autoredraw")
|
||||
|
||||
o.spec("autoredraw", function() {
|
||||
var FRAME_BUDGET = Math.floor(1000 / 60)
|
||||
var $window, root, renderer, pubsub, spy
|
||||
o.beforeEach(function() {
|
||||
$window = domMock()
|
||||
root = $window.document.body
|
||||
renderer = coreRenderer($window)
|
||||
pubsub = apiPubSub()
|
||||
spy = o.spy()
|
||||
})
|
||||
|
||||
o("returns self-trigger", function() {
|
||||
var run = autoredraw(root, renderer, pubsub, spy)
|
||||
|
||||
run()
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
|
||||
o("null renderer doesn't throw", function(done) {
|
||||
autoredraw(root, null, pubsub, spy)
|
||||
done()
|
||||
})
|
||||
|
||||
o("null pubsub doesn't throw", function(done) {
|
||||
autoredraw(root, renderer, null, spy)
|
||||
done()
|
||||
})
|
||||
|
||||
o("registers onevent", function() {
|
||||
autoredraw(root, renderer, pubsub, spy)
|
||||
|
||||
renderer.render(root, {tag: "div", attrs: {onclick: function() {}}})
|
||||
|
||||
var e = $window.document.createEvent("MouseEvents")
|
||||
e.initEvent("click", true, true)
|
||||
root.firstChild.dispatchEvent(e)
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
|
||||
o("registers pubsub", function() {
|
||||
autoredraw(root, renderer, pubsub, spy)
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
|
||||
o("re-registering pubsub works", function() {
|
||||
autoredraw(root, renderer, pubsub, spy)
|
||||
autoredraw(root, renderer, pubsub, spy)
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
|
||||
o("throttles", function(done) {
|
||||
var run = autoredraw(root, renderer, pubsub, spy)
|
||||
|
||||
run()
|
||||
run()
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
|
||||
setTimeout(function() {
|
||||
o(spy.callCount).equals(2)
|
||||
|
||||
done()
|
||||
}, FRAME_BUDGET)
|
||||
})
|
||||
|
||||
o("does not redraw if e.redraw is false", function() {
|
||||
autoredraw(root, renderer, pubsub, spy)
|
||||
|
||||
renderer.render(root, {tag: "div", attrs: {onclick: function(e) {e.redraw = false}}})
|
||||
|
||||
var e = $window.document.createEvent("MouseEvents")
|
||||
e.initEvent("click", true, true)
|
||||
root.firstChild.dispatchEvent(e)
|
||||
|
||||
o(spy.callCount).equals(0)
|
||||
})
|
||||
|
||||
})
|
||||
|
|
@ -5,20 +5,20 @@ var domMock = require("../../test-utils/domMock")
|
|||
|
||||
var m = require("../../render/hyperscript")
|
||||
var coreRenderer = require("../../render/render")
|
||||
var apiPubSub = require("../../api/pubsub")
|
||||
var apiRedraw = require("../../api/redraw")
|
||||
var apiMounter = require("../../api/mount")
|
||||
|
||||
o.spec("mount", function() {
|
||||
var FRAME_BUDGET = Math.floor(1000 / 60)
|
||||
var $window, root, redraw, mount, render
|
||||
var $window, root, redrawService, mount, render
|
||||
|
||||
o.beforeEach(function() {
|
||||
$window = domMock()
|
||||
|
||||
root = $window.document.body
|
||||
|
||||
redraw = apiPubSub()
|
||||
mount = apiMounter(coreRenderer($window), redraw)
|
||||
redrawService = apiRedraw($window)
|
||||
mount = apiMounter(redrawService)
|
||||
render = coreRenderer($window).render
|
||||
})
|
||||
|
||||
|
|
@ -42,18 +42,16 @@ o.spec("mount", function() {
|
|||
o(root.firstChild.nodeName).equals("DIV")
|
||||
})
|
||||
|
||||
o("mounting null deletes `redraw` from `root`", function() {
|
||||
o("mounting null unmounts", function() {
|
||||
mount(root, {
|
||||
view : function() {
|
||||
return m("div")
|
||||
}
|
||||
})
|
||||
|
||||
o(typeof root.redraw).equals('function')
|
||||
|
||||
mount(root, null)
|
||||
|
||||
o(typeof root.redraw).equals('undefined')
|
||||
o(root.childNodes.length).equals(0)
|
||||
})
|
||||
|
||||
o("redraws on events", function(done) {
|
||||
|
|
@ -206,7 +204,7 @@ o.spec("mount", function() {
|
|||
o(oninit.callCount).equals(1)
|
||||
o(onupdate.callCount).equals(0)
|
||||
|
||||
redraw.publish()
|
||||
redrawService.redraw()
|
||||
|
||||
// Wrapped to give time for the rate-limited redraw to fire
|
||||
setTimeout(function() {
|
||||
|
|
|
|||
|
|
@ -1,75 +0,0 @@
|
|||
"use strict"
|
||||
|
||||
var o = require("../../ospec/ospec")
|
||||
var apiPubSub = require("../../api/pubsub")
|
||||
|
||||
o.spec("pubsub", function() {
|
||||
var pubsub
|
||||
o.beforeEach(function() {
|
||||
pubsub = apiPubSub()
|
||||
})
|
||||
|
||||
o("shouldn't error if there are no renderers", function() {
|
||||
pubsub.publish()
|
||||
})
|
||||
|
||||
o("should run a single renderer entry", function() {
|
||||
var spy = o.spy()
|
||||
|
||||
pubsub.subscribe(spy)
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
|
||||
pubsub.publish()
|
||||
pubsub.publish()
|
||||
pubsub.publish()
|
||||
|
||||
o(spy.callCount).equals(4)
|
||||
})
|
||||
|
||||
o("should run all renderer entries", function() {
|
||||
var spy1 = o.spy()
|
||||
var spy2 = o.spy()
|
||||
var spy3 = o.spy()
|
||||
|
||||
pubsub.subscribe(spy1)
|
||||
pubsub.subscribe(spy2)
|
||||
pubsub.subscribe(spy3)
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
o(spy1.callCount).equals(1)
|
||||
o(spy2.callCount).equals(1)
|
||||
o(spy3.callCount).equals(1)
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
o(spy1.callCount).equals(2)
|
||||
o(spy2.callCount).equals(2)
|
||||
o(spy3.callCount).equals(2)
|
||||
})
|
||||
|
||||
o("should stop running after unsubscribe", function() {
|
||||
var spy = o.spy()
|
||||
|
||||
pubsub.subscribe(spy)
|
||||
pubsub.unsubscribe(spy)
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
o(spy.callCount).equals(0)
|
||||
})
|
||||
|
||||
o("does nothing on invalid unsubscribe", function() {
|
||||
var spy = o.spy()
|
||||
|
||||
pubsub.subscribe(spy)
|
||||
pubsub.unsubscribe(null)
|
||||
|
||||
pubsub.publish()
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
})
|
||||
82
api/tests/test-redraw.js
Normal file
82
api/tests/test-redraw.js
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
"use strict"
|
||||
|
||||
var o = require("../../ospec/ospec")
|
||||
var domMock = require("../../test-utils/domMock")
|
||||
var apiRedraw = require("../../api/redraw")
|
||||
|
||||
o.spec("redrawService", function() {
|
||||
var root, redrawService, $document
|
||||
o.beforeEach(function() {
|
||||
var $window = domMock()
|
||||
root = $window.document.body
|
||||
redrawService = apiRedraw($window)
|
||||
$document = $window.document
|
||||
})
|
||||
|
||||
o("shouldn't error if there are no renderers", function() {
|
||||
redrawService.redraw()
|
||||
})
|
||||
|
||||
o("should run a single renderer entry", function() {
|
||||
var spy = o.spy()
|
||||
|
||||
redrawService.subscribe(root, spy)
|
||||
|
||||
redrawService.redraw()
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
|
||||
redrawService.redraw()
|
||||
redrawService.redraw()
|
||||
redrawService.redraw()
|
||||
|
||||
o(spy.callCount).equals(4)
|
||||
})
|
||||
|
||||
o("should run all renderer entries", function() {
|
||||
var el1 = $document.createElement("div")
|
||||
var el2 = $document.createElement("div")
|
||||
var el3 = $document.createElement("div")
|
||||
var spy1 = o.spy()
|
||||
var spy2 = o.spy()
|
||||
var spy3 = o.spy()
|
||||
|
||||
redrawService.subscribe(el1, spy1)
|
||||
redrawService.subscribe(el2, spy2)
|
||||
redrawService.subscribe(el3, spy3)
|
||||
|
||||
redrawService.redraw()
|
||||
|
||||
o(spy1.callCount).equals(1)
|
||||
o(spy2.callCount).equals(1)
|
||||
o(spy3.callCount).equals(1)
|
||||
|
||||
redrawService.redraw()
|
||||
|
||||
o(spy1.callCount).equals(2)
|
||||
o(spy2.callCount).equals(2)
|
||||
o(spy3.callCount).equals(2)
|
||||
})
|
||||
|
||||
o("should stop running after unsubscribe", function() {
|
||||
var spy = o.spy()
|
||||
|
||||
redrawService.subscribe(root, spy)
|
||||
redrawService.unsubscribe(root, spy)
|
||||
|
||||
redrawService.redraw()
|
||||
|
||||
o(spy.callCount).equals(0)
|
||||
})
|
||||
|
||||
o("does nothing on invalid unsubscribe", function() {
|
||||
var spy = o.spy()
|
||||
|
||||
redrawService.subscribe(root, spy)
|
||||
redrawService.unsubscribe(null)
|
||||
|
||||
redrawService.redraw()
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
})
|
||||
|
|
@ -6,25 +6,23 @@ var browserMock = require("../../test-utils/browserMock")
|
|||
|
||||
var m = require("../../render/hyperscript")
|
||||
var coreRenderer = require("../../render/render")
|
||||
var apiPubSub = require("../../api/pubsub")
|
||||
var apiRedraw = require("../../api/redraw")
|
||||
var apiRouter = require("../../api/router")
|
||||
var apiMounter = require("../../api/mount")
|
||||
|
||||
o.spec("route", function() {
|
||||
void [{protocol: "http:", hostname: "localhost"}, {protocol: "file:", hostname: "/"}].forEach(function(env) {
|
||||
void ["#", "?", "", "#!", "?!", "/foo"].forEach(function(prefix) {
|
||||
o.spec("using prefix `" + prefix + "` starting on " + env.protocol + "//" + env.hostname, function() {
|
||||
var FRAME_BUDGET = Math.floor(1000 / 60)
|
||||
var $window, root, redraw, mount, route
|
||||
var $window, root, redrawService, route
|
||||
|
||||
o.beforeEach(function() {
|
||||
$window = browserMock(env)
|
||||
|
||||
root = $window.document.body
|
||||
|
||||
redraw = apiPubSub()
|
||||
mount = apiMounter(coreRenderer($window), redraw)
|
||||
route = apiRouter($window, mount)
|
||||
redrawService = apiRedraw($window)
|
||||
route = apiRouter($window, redrawService)
|
||||
route.prefix(prefix)
|
||||
})
|
||||
|
||||
|
|
@ -59,7 +57,7 @@ o.spec("route", function() {
|
|||
|
||||
o(view.callCount).equals(1)
|
||||
|
||||
redraw.publish(true)
|
||||
redrawService.redraw()
|
||||
|
||||
o(view.callCount).equals(2)
|
||||
|
||||
|
|
@ -122,7 +120,7 @@ o.spec("route", function() {
|
|||
|
||||
o(oninit.callCount).equals(1)
|
||||
|
||||
redraw.publish(true)
|
||||
redrawService.redraw()
|
||||
|
||||
o(onupdate.callCount).equals(1)
|
||||
})
|
||||
|
|
@ -403,7 +401,7 @@ o.spec("route", function() {
|
|||
o(matchCount).equals(1)
|
||||
o(renderCount).equals(1)
|
||||
|
||||
redraw.publish(true)
|
||||
redrawService.redraw()
|
||||
|
||||
o(matchCount).equals(1)
|
||||
o(renderCount).equals(2)
|
||||
|
|
@ -505,7 +503,7 @@ o.spec("route", function() {
|
|||
o(view.callCount).equals(1)
|
||||
o(onmatch.callCount).equals(1)
|
||||
|
||||
redraw.publish(true)
|
||||
redrawService.redraw()
|
||||
|
||||
o(view.callCount).equals(2)
|
||||
o(onmatch.callCount).equals(1)
|
||||
|
|
|
|||
|
|
@ -1,90 +0,0 @@
|
|||
"use strict"
|
||||
|
||||
var o = require("../../ospec/ospec")
|
||||
var callAsync = require("../../test-utils/callAsync")
|
||||
var throttle = require("../../api/throttle")
|
||||
|
||||
o.spec("throttle", function() {
|
||||
var FRAME_BUDGET = Math.floor(1000 / 60)
|
||||
var spy, throttled
|
||||
o.beforeEach(function() {
|
||||
spy = o.spy()
|
||||
throttled = throttle(spy)
|
||||
})
|
||||
|
||||
o("runs first call synchronously", function() {
|
||||
throttled()
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
|
||||
o("throttles subsequent synchronous calls", function(done) {
|
||||
throttled()
|
||||
throttled()
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
|
||||
setTimeout(function() {
|
||||
o(spy.callCount).equals(2)
|
||||
|
||||
done()
|
||||
}, FRAME_BUDGET) //this delay is much higher than 16.6ms due to setTimeout clamp and other runtime costs
|
||||
})
|
||||
|
||||
o("calls after threshold", function(done) {
|
||||
throttled()
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
|
||||
setTimeout(function(t) {
|
||||
throttled()
|
||||
|
||||
o(spy.callCount).equals(2)
|
||||
|
||||
done()
|
||||
}, FRAME_BUDGET)
|
||||
|
||||
})
|
||||
|
||||
o("throttles before threshold", function(done) {
|
||||
throttled()
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
|
||||
callAsync(function(t) {
|
||||
throttled()
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
o("it only runs once per tick", function(done) {
|
||||
throttled()
|
||||
throttled()
|
||||
throttled()
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
|
||||
setTimeout(function() {
|
||||
o(spy.callCount).equals(2)
|
||||
|
||||
done()
|
||||
}, FRAME_BUDGET)
|
||||
})
|
||||
|
||||
o("it supports forcing a synchronous redraw", function(done) {
|
||||
throttled()
|
||||
throttled()
|
||||
throttled(true)
|
||||
|
||||
o(spy.callCount).equals(2)
|
||||
|
||||
setTimeout(function() {
|
||||
o(spy.callCount).equals(3)
|
||||
|
||||
done()
|
||||
}, FRAME_BUDGET)
|
||||
})
|
||||
})
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
"use strict"
|
||||
|
||||
module.exports = function(callback) {
|
||||
//60fps translates to 16.6ms, round it down since setTimeout requires int
|
||||
var time = 16
|
||||
var last = 0, pending = null
|
||||
var timeout = typeof requestAnimationFrame === "function" ? requestAnimationFrame : setTimeout
|
||||
return function(synchronous) {
|
||||
var now = Date.now()
|
||||
if (synchronous === true || last === 0 || now - last >= time) {
|
||||
last = now
|
||||
callback()
|
||||
}
|
||||
else if (pending === null) {
|
||||
pending = timeout(function() {
|
||||
pending = null
|
||||
callback()
|
||||
last = Date.now()
|
||||
}, time - (now - last))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -32,8 +32,9 @@ function run(input, output) {
|
|||
def = def || "", variable = variable || "", eq = eq || "", rest = rest || ""
|
||||
if (def[0] === ",") def = "\nvar ", pre = "\n"
|
||||
var dependency = resolve(filepath, filename)
|
||||
var code = process(dependency, pre + (modules[dependency] == null ? exportCode(filename, dependency, def, variable, eq, rest, uuid) : def + variable + eq + modules[dependency]))
|
||||
modules[dependency] = rest ? "_" + uuid : variable
|
||||
var localUUID = uuid // global uuid can update from nested `process` call, ensure same id is used on declaration and consumption
|
||||
var code = process(dependency, pre + (modules[dependency] == null ? exportCode(filename, dependency, def, variable, eq, rest, localUUID) : def + variable + eq + modules[dependency]))
|
||||
modules[dependency] = rest ? "_" + localUUID : variable
|
||||
uuid++
|
||||
return code + rest
|
||||
})
|
||||
|
|
@ -116,7 +117,7 @@ function run(input, output) {
|
|||
code = "new function() {\n" + code + "\n}"
|
||||
|
||||
if (!isFile(output) || code !== read(output)) {
|
||||
try {new Function(code); console.log("build completed at " + new Date())} catch (e) {}
|
||||
//try {new Function(code); console.log("build completed at " + new Date())} catch (e) {}
|
||||
error = null
|
||||
fs.writeFileSync(output, code, "utf8")
|
||||
}
|
||||
|
|
@ -129,7 +130,7 @@ function run(input, output) {
|
|||
module.exports = function(input, output, options) {
|
||||
run(input, output)
|
||||
if (options && options.watch) {
|
||||
fs.watch(process.cwd(), {recursive: true}, function(file) {
|
||||
fs.watch(process.cwd(), {recursive: true}, function(file, type) {
|
||||
if (typeof file === "string" && path.resolve(output) !== path.resolve(file)) run(input, output)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -273,6 +273,30 @@ o.spec("bundler", function() {
|
|||
remove("d.js")
|
||||
remove("out.js")
|
||||
})
|
||||
o("works if included multiple times", function() {
|
||||
write("a.js", `module.exports = 123`)
|
||||
write("b.js", `var a = require("./a").toString()\nmodule.exports = a`)
|
||||
write("c.js", `var a = require("./a").toString()\nvar b = require("./b")`)
|
||||
bundle(ns + "c.js", ns + "out.js")
|
||||
|
||||
o(read("out.js")).equals(`new function() {\nvar _0 = 123\nvar a = _0.toString()\nvar a0 = _0.toString()\nvar b = a0\n}`)
|
||||
|
||||
remove("a.js")
|
||||
remove("b.js")
|
||||
remove("c.js")
|
||||
})
|
||||
o("works if included multiple times reverse", function() {
|
||||
write("a.js", `module.exports = 123`)
|
||||
write("b.js", `var a = require("./a").toString()\nmodule.exports = a`)
|
||||
write("c.js", `var b = require("./b")\nvar a = require("./a").toString()`)
|
||||
bundle(ns + "c.js", ns + "out.js")
|
||||
|
||||
o(read("out.js")).equals(`new function() {\nvar _0 = 123\nvar a0 = _0.toString()\nvar b = a0\nvar a = _0.toString()\n}`)
|
||||
|
||||
remove("a.js")
|
||||
remove("b.js")
|
||||
remove("c.js")
|
||||
})
|
||||
o("reuses binding if possible", function() {
|
||||
write("a.js", `var b = require("./b")\nvar c = require("./c")`)
|
||||
write("b.js", `var d = require("./d")\nmodule.exports = function() {return d + 1}`)
|
||||
|
|
|
|||
6
index.js
6
index.js
|
|
@ -4,13 +4,13 @@ var m = require("./hyperscript")
|
|||
var requestService = require("./request")
|
||||
var redrawService = require("./redraw")
|
||||
|
||||
requestService.setCompletionCallback(redrawService.publish)
|
||||
requestService.setCompletionCallback(redrawService.redraw)
|
||||
|
||||
m.mount = require("./mount")
|
||||
m.route = require("./route")
|
||||
m.withAttr = require("./util/withAttr")
|
||||
m.render = require("./render").render
|
||||
m.redraw = redrawService.publish
|
||||
m.render = redrawService.render
|
||||
m.redraw = redrawService.redraw
|
||||
m.request = requestService.request
|
||||
m.jsonp = requestService.jsonp
|
||||
m.parseQueryString = require("./querystring/parse")
|
||||
|
|
|
|||
278
mithril.js
278
mithril.js
|
|
@ -328,22 +328,7 @@ var _8 = function($window, Promise) {
|
|||
return {request: request, jsonp: jsonp, setCompletionCallback: setCompletionCallback}
|
||||
}
|
||||
var requestService = _8(window, PromisePolyfill)
|
||||
var _11 = function() {
|
||||
var callbacks = []
|
||||
function unsubscribe(callback) {
|
||||
var index = callbacks.indexOf(callback)
|
||||
if (index > -1) callbacks.splice(index, 1)
|
||||
}
|
||||
function publish() {
|
||||
for (var i = 0; i < callbacks.length; i++) {
|
||||
callbacks[i].apply(this, arguments)
|
||||
}
|
||||
}
|
||||
return {subscribe: callbacks.push.bind(callbacks), unsubscribe: unsubscribe, publish: publish}
|
||||
}
|
||||
var redrawService = _11()
|
||||
requestService.setCompletionCallback(redrawService.publish)
|
||||
var _13 = function($window) {
|
||||
var coreRenderer = function($window) {
|
||||
var $doc = $window.document
|
||||
var $emptyFragment = $doc.createDocumentFragment()
|
||||
var onevent
|
||||
|
|
@ -642,8 +627,8 @@ var _13 = function($window) {
|
|||
for (var i = 0; i < end; i++) {
|
||||
var vnode = vnodes[i]
|
||||
if (vnode != null) {
|
||||
var key1 = vnode.key
|
||||
if (key1 != null) map[key1] = i
|
||||
var key2 = vnode.key
|
||||
if (key2 != null) map[key2] = i
|
||||
}
|
||||
}
|
||||
return map
|
||||
|
|
@ -749,34 +734,34 @@ var _13 = function($window) {
|
|||
}
|
||||
//attrs2
|
||||
function setAttrs(vnode, attrs2, ns) {
|
||||
for (var key1 in attrs2) {
|
||||
setAttr(vnode, key1, null, attrs2[key1], ns)
|
||||
for (var key2 in attrs2) {
|
||||
setAttr(vnode, key2, null, attrs2[key2], ns)
|
||||
}
|
||||
}
|
||||
function setAttr(vnode, key1, old, value, ns) {
|
||||
function setAttr(vnode, key2, old, value, ns) {
|
||||
var element = vnode.dom
|
||||
if (key1 === "key" || (old === value && !isFormAttribute(vnode, key1)) && typeof value !== "object" || typeof value === "undefined" || isLifecycleMethod(key1)) return
|
||||
var nsLastIndex = key1.indexOf(":")
|
||||
if (nsLastIndex > -1 && key1.substr(0, nsLastIndex) === "xlink") {
|
||||
element.setAttributeNS("http://www.w3.org/1999/xlink", key1.slice(nsLastIndex + 1), value)
|
||||
if (key2 === "key" || (old === value && !isFormAttribute(vnode, key2)) && typeof value !== "object" || typeof value === "undefined" || isLifecycleMethod(key2)) return
|
||||
var nsLastIndex = key2.indexOf(":")
|
||||
if (nsLastIndex > -1 && key2.substr(0, nsLastIndex) === "xlink") {
|
||||
element.setAttributeNS("http://www.w3.org/1999/xlink", key2.slice(nsLastIndex + 1), value)
|
||||
}
|
||||
else if (key1[0] === "o" && key1[1] === "n" && typeof value === "function") updateEvent(vnode, key1, value)
|
||||
else if (key1 === "style") updateStyle(element, old, value)
|
||||
else if (key1 in element && !isAttribute(key1) && ns === undefined) {
|
||||
else if (key2[0] === "o" && key2[1] === "n" && typeof value === "function") updateEvent(vnode, key2, value)
|
||||
else if (key2 === "style") updateStyle(element, old, value)
|
||||
else if (key2 in element && !isAttribute(key2) && ns === undefined) {
|
||||
//setting input[value] to same value by typing on focused element moves cursor to end in Chrome
|
||||
if (vnode.tag === "input" && key1 === "value" && vnode.dom.value === value && vnode.dom === $doc.activeElement) return
|
||||
if (vnode.tag === "input" && key2 === "value" && vnode.dom.value === value && vnode.dom === $doc.activeElement) return
|
||||
//setting select[value] to same value while having select open blinks select dropdown in Chrome
|
||||
if (vnode.tag === "select" && key1 === "value" && vnode.dom.value === value && vnode.dom === $doc.activeElement) return
|
||||
if (vnode.tag === "select" && key2 === "value" && vnode.dom.value === value && vnode.dom === $doc.activeElement) return
|
||||
//setting option[value] to same value while having select open blinks select dropdown in Chrome
|
||||
if (vnode.tag === "option" && key1 === "value" && vnode.dom.value === value) return
|
||||
element[key1] = value
|
||||
if (vnode.tag === "option" && key2 === "value" && vnode.dom.value === value) return
|
||||
element[key2] = value
|
||||
}
|
||||
else {
|
||||
if (typeof value === "boolean") {
|
||||
if (value) element.setAttribute(key1, "")
|
||||
else element.removeAttribute(key1)
|
||||
if (value) element.setAttribute(key2, "")
|
||||
else element.removeAttribute(key2)
|
||||
}
|
||||
else element.setAttribute(key1 === "className" ? "class" : key1, value)
|
||||
else element.setAttribute(key2 === "className" ? "class" : key2, value)
|
||||
}
|
||||
}
|
||||
function setLateAttrs(vnode) {
|
||||
|
|
@ -788,16 +773,16 @@ var _13 = function($window) {
|
|||
}
|
||||
function updateAttrs(vnode, old, attrs2, ns) {
|
||||
if (attrs2 != null) {
|
||||
for (var key1 in attrs2) {
|
||||
setAttr(vnode, key1, old && old[key1], attrs2[key1], ns)
|
||||
for (var key2 in attrs2) {
|
||||
setAttr(vnode, key2, old && old[key2], attrs2[key2], ns)
|
||||
}
|
||||
}
|
||||
if (old != null) {
|
||||
for (var key1 in old) {
|
||||
if (attrs2 == null || !(key1 in attrs2)) {
|
||||
if (key1 === "className") key1 = "class"
|
||||
if (key1[0] === "o" && key1[1] === "n" && !isLifecycleMethod(key1)) updateEvent(vnode, key1, undefined)
|
||||
else if (key1 !== "key") vnode.dom.removeAttribute(key1)
|
||||
for (var key2 in old) {
|
||||
if (attrs2 == null || !(key2 in attrs2)) {
|
||||
if (key2 === "className") key2 = "class"
|
||||
if (key2[0] === "o" && key2[1] === "n" && !isLifecycleMethod(key2)) updateEvent(vnode, key2, undefined)
|
||||
else if (key2 !== "key") vnode.dom.removeAttribute(key2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -821,32 +806,32 @@ var _13 = function($window) {
|
|||
else if (typeof style === "string") element.style.cssText = style
|
||||
else {
|
||||
if (typeof old === "string") element.style.cssText = ""
|
||||
for (var key1 in style) {
|
||||
element.style[key1] = style[key1]
|
||||
for (var key2 in style) {
|
||||
element.style[key2] = style[key2]
|
||||
}
|
||||
if (old != null && typeof old !== "string") {
|
||||
for (var key1 in old) {
|
||||
if (!(key1 in style)) element.style[key1] = ""
|
||||
for (var key2 in old) {
|
||||
if (!(key2 in style)) element.style[key2] = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//event
|
||||
function updateEvent(vnode, key1, value) {
|
||||
function updateEvent(vnode, key2, value) {
|
||||
var element = vnode.dom
|
||||
var callback = function(e) {
|
||||
var result = value.call(element, e)
|
||||
if (typeof onevent === "function") onevent.call(element, e)
|
||||
return result
|
||||
}
|
||||
if (key1 in element) element[key1] = typeof value === "function" ? callback : null
|
||||
if (key2 in element) element[key2] = typeof value === "function" ? callback : null
|
||||
else {
|
||||
var eventName = key1.slice(2)
|
||||
var eventName = key2.slice(2)
|
||||
if (vnode.events === undefined) vnode.events = {}
|
||||
if (vnode.events[key1] != null) element.removeEventListener(eventName, vnode.events[key1], false)
|
||||
if (vnode.events[key2] != null) element.removeEventListener(eventName, vnode.events[key2], false)
|
||||
if (typeof value === "function") {
|
||||
vnode.events[key1] = callback
|
||||
element.addEventListener(eventName, vnode.events[key1], false)
|
||||
vnode.events[key2] = callback
|
||||
element.addEventListener(eventName, vnode.events[key2], false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -888,79 +873,90 @@ var _13 = function($window) {
|
|||
}
|
||||
return {render: render, setEventCallback: setEventCallback}
|
||||
}
|
||||
var renderService = _13(window)
|
||||
var throttle = function(callback1) {
|
||||
var _11 = function($window) {
|
||||
var renderService = coreRenderer($window)
|
||||
renderService.setEventCallback(function(e) {
|
||||
if (e.redraw !== false) redraw()
|
||||
})
|
||||
|
||||
var callbacks = []
|
||||
function subscribe(key1, callback) {
|
||||
unsubscribe(key1)
|
||||
callbacks.push(key1, callback)
|
||||
}
|
||||
function unsubscribe(key1) {
|
||||
var index = callbacks.indexOf(key1)
|
||||
if (index > -1) callbacks.splice(index, 2)
|
||||
}
|
||||
function redraw() {
|
||||
for (var i = 1; i < callbacks.length; i += 2) {
|
||||
callbacks[i]()
|
||||
}
|
||||
}
|
||||
return {subscribe: subscribe, unsubscribe: unsubscribe, redraw: redraw, render: renderService.render}
|
||||
}
|
||||
var redrawService = _11(window)
|
||||
requestService.setCompletionCallback(redrawService.redraw)
|
||||
var _16 = function(redrawService0) {
|
||||
function throttle(callback0) {
|
||||
//60fps translates to 16.6ms, round it down since setTimeout requires int
|
||||
var time = 16
|
||||
var last = 0, pending = null
|
||||
var timeout = typeof requestAnimationFrame === "function" ? requestAnimationFrame : setTimeout
|
||||
return function(synchronous) {
|
||||
return function() {
|
||||
var now = Date.now()
|
||||
if (synchronous === true || last === 0 || now - last >= time) {
|
||||
if (last === 0 || now - last >= time) {
|
||||
last = now
|
||||
callback1()
|
||||
callback0()
|
||||
}
|
||||
else if (pending === null) {
|
||||
pending = timeout(function() {
|
||||
pending = null
|
||||
callback1()
|
||||
callback0()
|
||||
last = Date.now()
|
||||
}, time - (now - last))
|
||||
}
|
||||
}
|
||||
}
|
||||
var autoredraw = function(root, renderer, pubsub, callback0) {
|
||||
var run1 = throttle(callback0)
|
||||
if (renderer != null) {
|
||||
renderer.setEventCallback(function(e) {
|
||||
if (e.redraw !== false) pubsub.publish()
|
||||
})
|
||||
}
|
||||
if (pubsub != null) {
|
||||
if (root.redraw) pubsub.unsubscribe(root.redraw)
|
||||
pubsub.subscribe(run1)
|
||||
}
|
||||
return root.redraw = run1
|
||||
}
|
||||
var _17 = function(renderer, pubsub) {
|
||||
|
||||
return function(root, component) {
|
||||
if (component === null) {
|
||||
renderer.render(root, [])
|
||||
pubsub.unsubscribe(root.redraw)
|
||||
delete root.redraw
|
||||
redrawService0.render(root, [])
|
||||
redrawService0.unsubscribe(root)
|
||||
return
|
||||
}
|
||||
|
||||
if (component.view == null) throw new Error("m.mount(element, component) expects a component, not a vnode")
|
||||
var run0 = autoredraw(root, renderer, pubsub, function() {
|
||||
renderer.render(root, Vnode(component, undefined, undefined, undefined, undefined, undefined))
|
||||
|
||||
var run0 = throttle(function() {
|
||||
redrawService0.render(root, Vnode(component))
|
||||
})
|
||||
redrawService0.subscribe(root, run0)
|
||||
run0()
|
||||
}
|
||||
}
|
||||
m.mount = _17(renderService, redrawService)
|
||||
var mount = m.mount
|
||||
m.mount = _16(redrawService)
|
||||
var parseQueryString = function(string) {
|
||||
if (string === "" || string == null) return {}
|
||||
if (string.charAt(0) === "?") string = string.slice(1)
|
||||
var entries = string.split("&"), data0 = {}, counters = {}
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
var entry = entries[i].split("=")
|
||||
var key3 = decodeURIComponent(entry[0])
|
||||
var key4 = decodeURIComponent(entry[0])
|
||||
var value = entry.length === 2 ? decodeURIComponent(entry[1]) : ""
|
||||
if (value === "true") value = true
|
||||
else if (value === "false") value = false
|
||||
var levels = key3.split(/\]\[?|\[/)
|
||||
var levels = key4.split(/\]\[?|\[/)
|
||||
var cursor = data0
|
||||
if (key3.indexOf("[") > -1) levels.pop()
|
||||
if (key4.indexOf("[") > -1) levels.pop()
|
||||
for (var j = 0; j < levels.length; j++) {
|
||||
var level = levels[j], nextLevel = levels[j + 1]
|
||||
var isNumber = nextLevel == "" || !isNaN(parseInt(nextLevel, 10))
|
||||
var isValue = j === levels.length - 1
|
||||
if (level === "") {
|
||||
var key3 = levels.slice(0, j).join()
|
||||
if (counters[key3] == null) counters[key3] = 0
|
||||
level = counters[key3]++
|
||||
var key4 = levels.slice(0, j).join()
|
||||
if (counters[key4] == null) counters[key4] = 0
|
||||
level = counters[key4]++
|
||||
}
|
||||
if (cursor[level] == null) {
|
||||
cursor[level] = isValue ? value : isNumber ? [] : {}
|
||||
|
|
@ -982,11 +978,11 @@ var coreRouter = function($window) {
|
|||
}
|
||||
var asyncId
|
||||
function debounceAsync(f) {
|
||||
return function() {
|
||||
return function(e) {
|
||||
if (asyncId != null) return
|
||||
asyncId = callAsync0(function() {
|
||||
asyncId = null
|
||||
f()
|
||||
f(e)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -997,11 +993,11 @@ var coreRouter = function($window) {
|
|||
if (queryIndex > -1) {
|
||||
var queryEnd = hashIndex > -1 ? hashIndex : path.length
|
||||
var queryParams = parseQueryString(path.slice(queryIndex + 1, queryEnd))
|
||||
for (var key2 in queryParams) queryData[key2] = queryParams[key2]
|
||||
for (var key3 in queryParams) queryData[key3] = queryParams[key3]
|
||||
}
|
||||
if (hashIndex > -1) {
|
||||
var hashParams = parseQueryString(path.slice(hashIndex + 1))
|
||||
for (var key2 in hashParams) hashData[key2] = hashParams[key2]
|
||||
for (var key3 in hashParams) hashData[key3] = hashParams[key3]
|
||||
}
|
||||
return path.slice(0, pathEnd)
|
||||
}
|
||||
|
|
@ -1017,7 +1013,7 @@ var coreRouter = function($window) {
|
|||
var queryData = {}, hashData = {}
|
||||
path = parsePath(path, queryData, hashData)
|
||||
if (data != null) {
|
||||
for (var key2 in data) queryData[key2] = data[key2]
|
||||
for (var key3 in data) queryData[key3] = data[key3]
|
||||
path = path.replace(/:([^\/]+)/g, function(match2, token) {
|
||||
delete queryData[token]
|
||||
return data[token]
|
||||
|
|
@ -1030,16 +1026,16 @@ var coreRouter = function($window) {
|
|||
if (supportsPushState) {
|
||||
if (options && options.replace) $window.history.replaceState(null, null, prefix1 + path)
|
||||
else $window.history.pushState(null, null, prefix1 + path)
|
||||
$window.onpopstate()
|
||||
$window.onpopstate(true)
|
||||
}
|
||||
else $window.location.href = prefix1 + path
|
||||
}
|
||||
function defineRoutes(routes, resolve0, reject) {
|
||||
function defineRoutes(routes, resolve, reject) {
|
||||
if (supportsPushState) $window.onpopstate = debounceAsync(resolveRoute)
|
||||
else if (prefix1.charAt(0) === "#") $window.onhashchange = resolveRoute
|
||||
resolveRoute()
|
||||
resolveRoute(true)
|
||||
|
||||
function resolveRoute() {
|
||||
function resolveRoute(isRouteChange) {
|
||||
var path = getPath()
|
||||
var params = {}
|
||||
var pathname = parsePath(path, params, params)
|
||||
|
|
@ -1053,14 +1049,14 @@ var coreRouter = function($window) {
|
|||
for (var i = 0; i < keys.length; i++) {
|
||||
params[keys[i].replace(/:|\./g, "")] = decodeURIComponent(values[i])
|
||||
}
|
||||
resolve0(routes[route0], params, path, route0)
|
||||
resolve(routes[route0], params, path, route0, !!isRouteChange)
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
reject(path, params)
|
||||
}
|
||||
return resolveRoute
|
||||
return function() {resolveRoute(false)}
|
||||
}
|
||||
function link(vnode2) {
|
||||
vnode2.dom.setAttribute("href", prefix1 + vnode2.attrs.href)
|
||||
|
|
@ -1075,64 +1071,60 @@ var coreRouter = function($window) {
|
|||
}
|
||||
return {setPrefix: setPrefix, getPath: getPath, setPath: setPath, defineRoutes: defineRoutes, link: link}
|
||||
}
|
||||
var _23 = function($window, mount0) {
|
||||
var router = coreRouter($window)
|
||||
var currentResolve, currentComponent, currentRender, currentArgs, currentPath
|
||||
var RouteComponent = {view: function() {
|
||||
return [currentRender(Vnode(currentComponent, null, currentArgs, undefined, undefined, undefined))]
|
||||
}}
|
||||
function defaultRender(vnode1) {
|
||||
return vnode1
|
||||
}
|
||||
var route = function(root, defaultRoute, routes) {
|
||||
currentComponent = "div"
|
||||
currentRender = defaultRender
|
||||
currentArgs = null
|
||||
mount0(root, RouteComponent)
|
||||
router.defineRoutes(routes, function(payload, args0, path) {
|
||||
var isResolver = typeof payload.view !== "function"
|
||||
var render1 = defaultRender
|
||||
var resolve = currentResolve = function (component) {
|
||||
if (resolve !== currentResolve) return
|
||||
currentResolve = null
|
||||
currentComponent = component != null ? component : isResolver ? "div" : payload
|
||||
currentRender = render1
|
||||
currentArgs = args0
|
||||
currentPath = path
|
||||
root.redraw(true)
|
||||
}
|
||||
var onmatch = function() {
|
||||
resolve()
|
||||
}
|
||||
if (isResolver) {
|
||||
if (typeof payload.render === "function") render1 = payload.render.bind(payload)
|
||||
if (typeof payload.onmatch === "function") onmatch = payload.onmatch
|
||||
}
|
||||
var _20 = function($window, redrawService0) {
|
||||
var routeService = coreRouter($window)
|
||||
|
||||
onmatch.call(payload, resolve, args0, path)
|
||||
}, function() {
|
||||
router.setPath(defaultRoute, null, {replace: true})
|
||||
})
|
||||
var identity = function(v) {return v}
|
||||
var current = {render: identity, component: null, path: null, resolve: null}
|
||||
var route = function(root, defaultRoute, routes) {
|
||||
if (root == null) throw new Error("Ensure the DOM element that was passed to `m.route` is not undefined")
|
||||
var render1 = function(resolver, component, params, path) {
|
||||
current.render = resolver.render || identity
|
||||
current.component = component
|
||||
current.path = path
|
||||
current.resolve = null
|
||||
redrawService0.render(root, current.render(Vnode(component, undefined, params)))
|
||||
}
|
||||
route.link = router.link
|
||||
route.prefix = router.setPrefix
|
||||
route.set = router.setPath
|
||||
route.get = function() {return currentPath}
|
||||
var run1 = routeService.defineRoutes(routes, function(component, params, path, route, isRouteChange) {
|
||||
if (component.view) render1({}, component, params, path)
|
||||
else {
|
||||
if (component.onmatch) {
|
||||
if (isRouteChange === false && current.path === path || current.resolve != null) render1(current, current.component, params)
|
||||
else {
|
||||
current.resolve = function(resolved) {
|
||||
render1(component, resolved, params, path)
|
||||
}
|
||||
component.onmatch(function(resolved) {
|
||||
if (current.path !== path && current.resolve != null) current.resolve(resolved)
|
||||
}, params, path)
|
||||
}
|
||||
}
|
||||
else render1(component, "div", params, path)
|
||||
}
|
||||
}, function() {
|
||||
routeService.setPath(defaultRoute)
|
||||
})
|
||||
redrawService0.subscribe(root, run1)
|
||||
}
|
||||
route.set = routeService.setPath
|
||||
route.get = function() {return current.path}
|
||||
route.prefix = routeService.setPrefix
|
||||
route.link = routeService.link
|
||||
return route
|
||||
}
|
||||
m.route = _23(window, mount)
|
||||
m.withAttr = function(attrName, callback2, context) {
|
||||
m.route = _20(window, redrawService)
|
||||
m.withAttr = function(attrName, callback1, context) {
|
||||
return function(e) {
|
||||
return callback2.call(context || this, attrName in e.currentTarget ? e.currentTarget[attrName] : e.currentTarget.getAttribute(attrName))
|
||||
return callback1.call(context || this, attrName in e.currentTarget ? e.currentTarget[attrName] : e.currentTarget.getAttribute(attrName))
|
||||
}
|
||||
}
|
||||
m.render = renderService.render
|
||||
m.redraw = redrawService.publish
|
||||
m.render = redrawService.render
|
||||
m.redraw = redrawService.redraw
|
||||
m.request = requestService.request
|
||||
m.jsonp = requestService.jsonp
|
||||
m.parseQueryString = parseQueryString
|
||||
m.buildQueryString = buildQueryString
|
||||
m.version = "1.0.0-rc.5"
|
||||
m.version = "1.0.0-rc.6"
|
||||
if (typeof module !== "undefined") module["exports"] = m
|
||||
else window.m = m
|
||||
}
|
||||
80
mithril.min.js
vendored
80
mithril.min.js
vendored
|
|
@ -1,40 +1,40 @@
|
|||
new function(){function m(a,b,k,e,l,h){return{tag:a,key:b,attrs:k,children:e,text:l,dom:h,domSize:void 0,state:{},events:void 0,instance:void 0,skip:!1}}function t(a){if(null==a||"string"!==typeof a&&null==a.view)throw Error("The selector must be either a string or a component.");if("string"===typeof a&&void 0===H[a]){for(var b,k,e=[],l={};b=O.exec(a);){var h=b[1],v=b[2];""===h&&""!==v?k=v:"#"===h?l.id=v:"."===h?e.push(v):"["===b[3][0]&&((h=b[6])&&(h=h.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),
|
||||
"class"===b[4]?e.push(h):l[b[4]]=h||!0)}0<e.length&&(l.className=e.join(" "));H[a]=function(a,b){var e=!1,h,f,w=a.className||a["class"],n;for(n in l)a[n]=l[n];void 0!==w&&(void 0!==a["class"]&&(a["class"]=void 0,a.className=w),void 0!==l.className&&(a.className=l.className+" "+w));for(n in a)if("key"!==n){e=!0;break}b instanceof Array&&1==b.length&&null!=b[0]&&"#"===b[0].tag?f=b[0].children:h=b;return m(k||"div",a.key,e?a:void 0,h,f,void 0)}}var p;null!=arguments[1]&&("object"!==typeof arguments[1]||
|
||||
void 0!==arguments[1].tag||arguments[1]instanceof Array)?e=1:(p=arguments[1],e=2);if(arguments.length===e+1)b=arguments[e]instanceof Array?arguments[e]:[arguments[e]];else for(b=[];e<arguments.length;e++)b.push(arguments[e]);return"string"===typeof a?H[a](p||{},m.normalizeChildren(b)):m(a,p&&p.key,p||{},m.normalizeChildren(b),void 0,void 0)}m.normalize=function(a){return a instanceof Array?m("[",void 0,void 0,m.normalizeChildren(a),void 0,void 0):null!=a&&"object"!==typeof a?m("#",void 0,void 0,a,
|
||||
void 0,void 0):a};m.normalizeChildren=function(a){for(var b=0;b<a.length;b++)a[b]=m.normalize(a[b]);return a};var O=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,H={};t.trust=function(a){null==a&&(a="");return m("<",void 0,void 0,a,void 0,void 0)};t.fragment=function(a,b){return m("[",a.key,a,m.normalizeChildren(b),void 0,void 0)};var y=function(a){function b(a,b){return function w(n){var u;try{if(!b||null==n||"object"!==typeof n&&"function"!==typeof n||"function"!==
|
||||
typeof(u=n.then))m(function(){b||0!==a.length||console.error("Possible unhandled promise rejection:",n);for(var e=0;e<a.length;e++)a[e](n);l.length=0;h.length=0;r.state=b;r.retry=function(){w(n)}});else{if(n===e)throw new TypeError("Promise can't be resolved w/ itself");k(u.bind(n))}}catch(F){p(F)}}}function k(a){function b(a){return function(b){0<f++||a(b)}}var f=0,e=b(p);try{a(b(v),e)}catch(n){e(n)}}if(!(this instanceof y))throw Error("Promise must be called with `new`");if("function"!==typeof a)throw new TypeError("executor must be a function");
|
||||
var e=this,l=[],h=[],v=b(l,!0),p=b(h,!1),r=e._instance={resolvers:l,rejectors:h},m="function"===typeof setImmediate?setImmediate:setTimeout;k(a)};y.prototype.then=function(a,b){function k(a,b,k,u){b.push(function(b){if("function"!==typeof a)k(b);else try{l(a(b))}catch(f){h&&h(f)}});"function"===typeof e.retry&&u===e.state&&e.retry()}var e=this._instance,l,h,v=new y(function(a,b){l=a;h=b});k(a,e.resolvers,l,!0);k(b,e.rejectors,h,!1);return v};y.prototype["catch"]=function(a){return this.then(null,
|
||||
a)};y.resolve=function(a){return a instanceof y?a:new y(function(b){b(a)})};y.reject=function(a){return new y(function(b,k){k(a)})};y.all=function(a){return new y(function(b,k){var e=a.length,l=0,h=[];if(0===a.length)b([]);else for(var v=0;v<a.length;v++)(function(v){function r(a){l++;h[v]=a;l===e&&b(h)}null==a[v]||"object"!==typeof a[v]&&"function"!==typeof a[v]||"function"!==typeof a[v].then?r(a[v]):a[v].then(r,k)})(v)})};y.race=function(a){return new y(function(b,k){for(var e=0;e<a.length;e++)a[e].then(b,
|
||||
k)})};"undefined"===typeof Promise&&("undefined"!==typeof window?window.Promise=y:"undefined"!==typeof global&&(global.Promise=y));var C=function(a){function b(a,e){if(e instanceof Array)for(var h=0;h<e.length;h++)b(a+"["+h+"]",e[h]);else if("[object Object]"===Object.prototype.toString.call(e))for(h in e)b(a+"["+h+"]",e[h]);else k.push(encodeURIComponent(a)+(null!=e&&""!==e?"="+encodeURIComponent(e):""))}if("[object Object]"!==Object.prototype.toString.call(a))return"";var k=[],e;for(e in a)b(e,
|
||||
a[e]);return k.join("&")},I=function(a,b){function k(){0===--u&&"function"===typeof q&&q()}function e(a){var f=a.then;a.then=function(){u++;var b=f.apply(a,arguments);b.then(k,function(a){k();throw a;});return e(b)};return a}function l(a,b){if(null==b)return a;for(var f=a.match(/:[^\/]+/gi)||[],e=0;e<f.length;e++){var h=f[e].slice(1);null!=b[h]&&(a=a.replace(f[e],b[h]),delete b[h])}return a}function h(a,b){var f=C(b);if(""!==f){var e=0>a.indexOf("?")?"?":"&";a+=e+f}return a}function v(a){try{return""!==
|
||||
a?JSON.parse(a):null}catch(w){throw Error(a);}}function p(a){return a.responseText}function r(a,b){if("function"===typeof a)if(b instanceof Array)for(var e=0;e<b.length;e++)b[e]=new a(b[e]);else return new a(b);return b}var m=0,u=0,q;return{request:function(f,k){return e(new b(function(b,e){if("string"===typeof f){var u=f;f=k||{};null==f.url&&(f.url=u)}null==f.method&&(f.method="GET");f.method=f.method.toUpperCase();u="boolean"===typeof f.useBody?f.useBody:"GET"!==f.method&&"TRACE"!==f.method;"function"!==
|
||||
typeof f.serialize&&(f.serialize="undefined"!==typeof FormData&&f.data instanceof FormData?function(a){return a}:JSON.stringify);"function"!==typeof f.deserialize&&(f.deserialize=v);"function"!==typeof f.extract&&(f.extract=p);f.url=l(f.url,f.data);u?f.data=f.serialize(f.data):f.url=h(f.url,f.data);var n=new a.XMLHttpRequest;n.open(f.method,f.url,"boolean"===typeof f.async?f.async:!0,"string"===typeof f.user?f.user:void 0,"string"===typeof f.password?f.password:void 0);f.serialize===JSON.stringify&&
|
||||
u&&n.setRequestHeader("Content-Type","application/json; charset=utf-8");f.deserialize===v&&n.setRequestHeader("Accept","application/json, text/*");f.withCredentials&&(n.withCredentials=f.withCredentials);"function"===typeof f.config&&(n=f.config(n,f)||n);n.onreadystatechange=function(){if(4===n.readyState)try{var a=f.extract!==p?f.extract(n,f):f.deserialize(f.extract(n,f));if(200<=n.status&&300>n.status||304===n.status)b(r(f.type,a));else{var h=Error(n.responseText),k;for(k in a)h[k]=a[k];e(h)}}catch(G){e(G)}};
|
||||
u&&null!=f.data?n.send(f.data):n.send()}))},jsonp:function(f){return e(new b(function(b,e){var n=f.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+m++,k=a.document.createElement("script");a[n]=function(e){k.parentNode.removeChild(k);b(r(f.type,e));delete a[n]};k.onerror=function(){k.parentNode.removeChild(k);e(Error("JSONP request failed"));delete a[n]};null==f.data&&(f.data={});f.url=l(f.url,f.data);f.data[f.callbackKey||"callback"]=n;k.src=h(f.url,f.data);a.document.documentElement.appendChild(k)}))},
|
||||
setCompletionCallback:function(a){q=a}}}(window,"undefined"!==typeof Promise?Promise:y),J=function(){var a=[];return{subscribe:a.push.bind(a),unsubscribe:function(b){b=a.indexOf(b);-1<b&&a.splice(b,1)},publish:function(){for(var b=0;b<a.length;b++)a[b].apply(this,arguments)}}}();I.setCompletionCallback(J.publish);var N=function(a){function b(c,g,a,b,e,f,h){for(;a<b;a++){var d=g[a];null!=d&&r(c,k(d,e,h),f)}}function k(c,g,a){var d=c.tag;null!=c.attrs&&t(c.attrs,c,g);if("string"===typeof d)switch(d){case "#":return c.dom=
|
||||
z.createTextNode(c.children);case "<":return e(c);case "[":var f=z.createDocumentFragment();null!=c.children&&(d=c.children,b(f,d,0,d.length,g,null,a));c.dom=f.firstChild;c.domSize=f.childNodes.length;return f;default:var h=c.tag;switch(c.tag){case "svg":a="http://www.w3.org/2000/svg";break;case "math":a="http://www.w3.org/1998/Math/MathML"}var E=(d=c.attrs)&&d.is,h=a?E?z.createElementNS(a,h,{is:E}):z.createElementNS(a,h):E?z.createElement(h,{is:E}):z.createElement(h);c.dom=h;if(null!=d)for(f in E=
|
||||
a,d)n(c,f,null,d[f],E);null!=c.attrs&&null!=c.attrs.contenteditable?y(c):(null!=c.text&&(""!==c.text?h.textContent=c.text:c.children=[m("#",void 0,void 0,c.text,void 0,void 0)]),null!=c.children&&(f=c.children,b(h,f,0,f.length,g,null,a),g=c.attrs,"select"===c.tag&&null!=g&&("value"in g&&n(c,"value",null,g.value,void 0),"selectedIndex"in g&&n(c,"selectedIndex",null,g.selectedIndex,void 0))));return h}else{c.state||(c.state={});P(c.state,c.tag);f=c.tag.view;if(null!=f.reentrantLock)c=G;else if(f.reentrantLock=
|
||||
!0,t(c.tag,c,g),c.instance=m.normalize(f.call(c.state,c)),f.reentrantLock=null,null!=c.instance){if(c.instance===c)throw Error("A view cannot return the vnode it received as arguments");g=k(c.instance,g,a);c.dom=c.instance.dom;c.domSize=null!=c.dom?c.instance.domSize:0;c=g}else c.domSize=0,c=G;return c}}function e(c){var a={caption:"table",thead:"table",tbody:"table",tfoot:"table",tr:"tbody",th:"tr",td:"tr",colgroup:"table",col:"colgroup"}[(c.children.match(/^\s*?<(\w+)/im)||[])[1]]||"div",a=z.createElement(a);
|
||||
a.innerHTML=c.children;c.dom=a.firstChild;c.domSize=a.childNodes.length;c=z.createDocumentFragment();for(var d;d=a.firstChild;)c.appendChild(d);return c}function l(c,a,d,f,e,n){if(a!==d&&(null!=a||null!=d))if(null==a)b(c,d,0,d.length,f,e,void 0);else if(null==d)u(a,0,a.length,d);else if(a.length===d.length&&null!=d[0]&&null==d[0].key)for(var g=0;g<a.length;g++)a[g]===d[g]||null==a[g]&&null==d[g]||(null==a[g]?r(c,k(d[g],f,n),p(a,g+1,e)):null==d[g]?u(a,g,g+1,d):h(c,a[g],d[g],f,p(a,g+1,e),!1,n));else{a:{if(null!=
|
||||
a.pool&&Math.abs(a.pool.length-d.length)<=Math.abs(a.length-d.length)&&(g=d[0]&&d[0].children&&d[0].children.length||0,Math.abs((a.pool[0]&&a.pool[0].children&&a.pool[0].children.length||0)-g)<=Math.abs((a[0]&&a[0].children&&a[0].children.length||0)-g))){g=!0;break a}g=!1}g&&(a=a.concat(a.pool));for(var A=0,l=0,q=a.length-1,B=d.length-1,w;q>=A&&B>=l;){var x=a[A],m=d[l];if(x!==m||g)if(null==x)A++;else if(null==m)l++;else if(x.key===m.key)A++,l++,h(c,x,m,f,p(a,A,e),g,n),g&&x.tag===m.tag&&r(c,v(x),e);
|
||||
else if(x=a[q],x!==m||g)if(null==x)q--;else if(null==m)l++;else if(x.key===m.key)h(c,x,m,f,p(a,q+1,e),g,n),(g||l<B)&&r(c,v(x),p(a,A,e)),q--,l++;else break;else q--,l++;else A++,l++}for(;q>=A&&B>=l;){x=a[q];m=d[B];if(x!==m||g)if(null==x)q--;else{if(null!=m)if(x.key===m.key)h(c,x,m,f,p(a,q+1,e),g,n),g&&x.tag===m.tag&&r(c,v(x),e),null!=x.dom&&(e=x.dom),q--;else{if(!w){w=a;var x=q,D={},z;for(z=0;z<x;z++){var t=w[z];null!=t&&(t=t.key,null!=t&&(D[t]=z))}w=D}null!=m&&(x=w[m.key],null!=x?(D=a[x],h(c,D,m,
|
||||
f,p(a,q+1,e),g,n),r(c,v(D),e),a[x].skip=!0,null!=D.dom&&(e=D.dom)):(m=k(m,f,void 0),r(c,m,e),e=m))}B--}else q--,B--;if(B<l)break}b(c,d,l,B+1,f,e,n);u(a,A,q+1,d)}}function h(a,g,d,b,u,q,w){var c=g.tag;if(c===d.tag){d.state=g.state;d.events=g.events;var A;var B;null!=d.attrs&&"function"===typeof d.attrs.onbeforeupdate&&(A=d.attrs.onbeforeupdate.call(d.state,d,g));"string"!==typeof d.tag&&"function"===typeof d.tag.onbeforeupdate&&(B=d.tag.onbeforeupdate.call(d.state,d,g));void 0===A&&void 0===B||A||
|
||||
B?A=!1:(d.dom=g.dom,d.domSize=g.domSize,d.instance=g.instance,A=!0);if(!A)if(null!=d.attrs&&M(d.attrs,d,b,q),"string"===typeof c)switch(c){case "#":g.children.toString()!==d.children.toString()&&(g.dom.nodeValue=d.children);d.dom=g.dom;break;case "<":g.children!==d.children?(v(g),r(a,e(d),u)):(d.dom=g.dom,d.domSize=g.domSize);break;case "[":l(a,g.children,d.children,b,u,w);g=0;b=d.children;d.dom=null;if(null!=b){for(var p=0;p<b.length;p++)a=b[p],null!=a&&null!=a.dom&&(null==d.dom&&(d.dom=a.dom),g+=
|
||||
a.domSize||1);1!==g&&(d.domSize=g)}break;default:a=w;u=d.dom=g.dom;switch(d.tag){case "svg":a="http://www.w3.org/2000/svg";break;case "math":a="http://www.w3.org/1998/Math/MathML"}"textarea"===d.tag&&(null==d.attrs&&(d.attrs={}),null!=d.text&&(d.attrs.value=d.text,d.text=void 0));q=g.attrs;w=d.attrs;c=a;if(null!=w)for(p in w)n(d,p,q&&q[p],w[p],c);if(null!=q)for(p in q)null!=w&&p in w||("className"===p&&(p="class"),"o"!==p[0]||"n"!==p[1]||L(p)?"key"!==p&&d.dom.removeAttribute(p):F(d,p,void 0));null!=
|
||||
d.attrs&&null!=d.attrs.contenteditable?y(d):null!=g.text&&null!=d.text&&""!==d.text?g.text.toString()!==d.text.toString()&&(g.dom.firstChild.nodeValue=d.text):(null!=g.text&&(g.children=[m("#",void 0,void 0,g.text,void 0,g.dom.firstChild)]),null!=d.text&&(d.children=[m("#",void 0,void 0,d.text,void 0,void 0)]),l(u,g.children,d.children,b,null,a))}else d.instance=m.normalize(d.tag.view.call(d.state,d)),M(d.tag,d,b,q),null!=d.instance?(null==g.instance?r(a,k(d.instance,b,w),u):h(a,g.instance,d.instance,
|
||||
b,u,q,w),d.dom=d.instance.dom,d.domSize=d.instance.domSize):null!=g.instance?(f(g.instance,null),d.dom=void 0,d.domSize=0):(d.dom=g.dom,d.domSize=g.domSize)}else f(g,null),r(a,k(d,b,w),u)}function v(a){var c=a.domSize;if(null!=c||null==a.dom){var d=z.createDocumentFragment();if(0<c){for(a=a.dom;--c;)d.appendChild(a.nextSibling);d.insertBefore(a,d.firstChild)}return d}return a.dom}function p(a,g,d){for(;g<a.length;g++)if(null!=a[g]&&null!=a[g].dom)return a[g].dom;return d}function r(a,g,d){d&&d.parentNode?
|
||||
a.insertBefore(g,d):a.appendChild(g)}function y(a){var c=a.children;if(null!=c&&1===c.length&&"<"===c[0].tag)c=c[0].children,a.dom.innerHTML!==c&&(a.dom.innerHTML=c);else if(null!=c||null!=a.text)throw Error("Child node of a contenteditable must be trusted");}function u(a,g,d,b){for(;g<d;g++){var c=a[g];null!=c&&(c.skip?c.skip=!1:f(c,b))}}function q(a){var c=!1;return function(){c||(c=!0,a())}}function f(a,g){function c(){if(++e===b&&(w(a),a.dom)){var c=a.domSize||1;if(1<c)for(var d=a.dom;--c;){var f=
|
||||
d.nextSibling,h=f.parentNode;null!=h&&h.removeChild(f)}c=a.dom;d=c.parentNode;null!=d&&d.removeChild(c);if(c=null!=g&&null==a.domSize)c=a.attrs,c=!(null!=c&&(c.oncreate||c.onupdate||c.onbeforeremove||c.onremove));c&&"string"===typeof a.tag&&(g.pool?g.pool.push(a):g.pool=[a])}}var b=1,e=0;a.attrs&&a.attrs.onbeforeremove&&(b++,a.attrs.onbeforeremove.call(a.state,a,q(c)));"string"!==typeof a.tag&&a.tag.onbeforeremove&&(b++,a.tag.onbeforeremove.call(a.state,a,q(c)));c()}function w(a){a.attrs&&a.attrs.onremove&&
|
||||
a.attrs.onremove.call(a.state,a);"string"!==typeof a.tag&&a.tag.onremove&&a.tag.onremove.call(a.state,a);if(null!=a.instance)w(a.instance);else if(a=a.children,a instanceof Array)for(var c=0;c<a.length;c++){var d=a[c];null!=d&&w(d)}}function n(a,g,d,b,e){var c=a.dom;if("key"!==g&&(d!==b||"value"===g||"checked"===g||"selectedIndex"===g||"selected"===g&&a.dom===z.activeElement||"object"===typeof b)&&"undefined"!==typeof b&&!L(g)){var f=g.indexOf(":");if(-1<f&&"xlink"===g.substr(0,f))c.setAttributeNS("http://www.w3.org/1999/xlink",
|
||||
g.slice(f+1),b);else if("o"===g[0]&&"n"===g[1]&&"function"===typeof b)F(a,g,b);else if("style"===g)if(a=d,a===b&&(c.style.cssText="",a=null),null==b)c.style.cssText="";else if("string"===typeof b)c.style.cssText=b;else{"string"===typeof a&&(c.style.cssText="");for(var h in b)c.style[h]=b[h];if(null!=a&&"string"!==typeof a)for(h in a)h in b||(c.style[h]="")}else g in c&&"href"!==g&&"list"!==g&&"form"!==g&&"width"!==g&&"height"!==g&&void 0===e?"input"===a.tag&&"value"===g&&a.dom.value===b&&a.dom===
|
||||
z.activeElement||"select"===a.tag&&"value"===g&&a.dom.value===b&&a.dom===z.activeElement||"option"===a.tag&&"value"===g&&a.dom.value===b||(c[g]=b):"boolean"===typeof b?b?c.setAttribute(g,""):c.removeAttribute(g):c.setAttribute("className"===g?"class":g,b)}}function L(a){return"oninit"===a||"oncreate"===a||"onupdate"===a||"onremove"===a||"onbeforeremove"===a||"onbeforeupdate"===a}function F(a,b,d){var c=a.dom,g=function(a){var b=d.call(c,a);"function"===typeof C&&C.call(c,a);return b};if(b in c)c[b]=
|
||||
"function"===typeof d?g:null;else{var e=b.slice(2);void 0===a.events&&(a.events={});null!=a.events[b]&&c.removeEventListener(e,a.events[b],!1);"function"===typeof d&&(a.events[b]=g,c.addEventListener(e,a.events[b],!1))}}function t(a,b,d){"function"===typeof a.oninit&&a.oninit.call(b.state,b);"function"===typeof a.oncreate&&d.push(a.oncreate.bind(b.state,b))}function M(a,b,d,e){e?t(a,b,d):"function"===typeof a.onupdate&&d.push(a.onupdate.bind(b.state,b))}function P(a,b){Object.keys(b).forEach(function(c){a[c]=
|
||||
b[c]})}var z=a.document,G=z.createDocumentFragment(),C;return{render:function(a,b){if(!a)throw Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");var d=[],c=z.activeElement;null==a.vnodes&&(a.textContent="");b instanceof Array||(b=[b]);l(a,a.vnodes,m.normalizeChildren(b),d,null,void 0);a.vnodes=b;for(var e=0;e<d.length;e++)d[e]();z.activeElement!==c&&c.focus()},setEventCallback:function(a){return C=a}}}(window),Q=function(a){var b=0,k=null,e="function"===typeof requestAnimationFrame?
|
||||
requestAnimationFrame:setTimeout;return function(l){var h=Date.now();!0===l||0===b||16<=h-b?(b=h,a()):null===k&&(k=e(function(){k=null;a();b=Date.now()},16-(h-b)))}},R=function(a,b,k,e){e=Q(e);null!=b&&b.setEventCallback(function(a){!1!==a.redraw&&k.publish()});null!=k&&(a.redraw&&k.unsubscribe(a.redraw),k.subscribe(e));return a.redraw=e};t.mount=function(a,b){return function(k,e){if(null===e)a.render(k,[]),b.unsubscribe(k.redraw),delete k.redraw;else{if(null==e.view)throw Error("m.mount(element, component) expects a component, not a vnode");
|
||||
R(k,a,b,function(){a.render(k,m(e,void 0,void 0,void 0,void 0,void 0))})()}}}(N,J);var K=function(a){if(""===a||null==a)return{};"?"===a.charAt(0)&&(a=a.slice(1));a=a.split("&");for(var b={},k={},e=0;e<a.length;e++){var l=a[e].split("="),h=decodeURIComponent(l[0]),l=2===l.length?decodeURIComponent(l[1]):"";"true"===l?l=!0:"false"===l&&(l=!1);var m=h.split(/\]\[?|\[/),p=b;-1<h.indexOf("[")&&m.pop();for(var r=0;r<m.length;r++){var h=m[r],t=m[r+1],t=""==t||!isNaN(parseInt(t,10)),u=r===m.length-1;""===
|
||||
h&&(h=m.slice(0,r).join(),null==k[h]&&(k[h]=0),h=k[h]++);null==p[h]&&(p[h]=u?l:t?[]:{});p=p[h]}}return b},S=function(a){function b(b){var e=a.location[b].replace(/(?:%[a-f89][a-f0-9])+/gim,decodeURIComponent);"pathname"===b&&"/"!==e[0]&&(e="/"+e);return e}function k(a){return function(){null==t&&(t=p(function(){t=null;a()}))}}function e(a,b,e){var f=a.indexOf("?"),h=a.indexOf("#"),k=-1<f?f:-1<h?h:a.length;if(-1<f){var f=K(a.slice(f+1,-1<h?h:a.length)),l;for(l in f)b[l]=f[l]}if(-1<h)for(l in b=K(a.slice(h+
|
||||
1)),b)e[l]=b[l];return a.slice(0,k)}function l(){switch(r.charAt(0)){case "#":return b("hash").slice(r.length);case "?":return b("search").slice(r.length)+b("hash");default:return b("pathname").slice(r.length)+b("search")+b("hash")}}function h(b,h,f){var k={},n={};b=e(b,k,n);if(null!=h){for(var l in h)k[l]=h[l];b=b.replace(/:([^\/]+)/g,function(a,b){delete k[b];return h[b]})}(l=C(k))&&(b+="?"+l);(n=C(n))&&(b+="#"+n);m?(f&&f.replace?a.history.replaceState(null,null,r+b):a.history.pushState(null,null,
|
||||
r+b),a.onpopstate()):a.location.href=r+b}var m="function"===typeof a.history.pushState,p="function"===typeof setImmediate?setImmediate:setTimeout,r="#!",t;return{setPrefix:function(a){r=a},getPath:l,setPath:h,defineRoutes:function(b,h,f){function q(){var a=l(),k={},m=e(a,k,k),q;for(q in b){var p=new RegExp("^"+q.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$");if(p.test(m)){m.replace(p,function(){for(var e=q.match(/:[^\/]+/g)||[],f=[].slice.call(arguments,1,-2),l=0;l<e.length;l++)k[e[l].replace(/:|\./g,
|
||||
"")]=decodeURIComponent(f[l]);h(b[q],k,a,q)});return}}f(a,k)}m?a.onpopstate=k(q):"#"===r.charAt(0)&&(a.onhashchange=q);q();return q},link:function(a){a.dom.setAttribute("href",r+a.attrs.href);a.dom.onclick=function(a){a.ctrlKey||a.metaKey||a.shiftKey||2===a.which||(a.preventDefault(),a.redraw=!1,a=this.getAttribute("href"),0===a.indexOf(r)&&(a=a.slice(r.length)),h(a,void 0,void 0))}}}};t.route=function(a,b){function k(a){return a}var e=S(a),l,h,t,p,r,y={view:function(){return[t(m(h,null,p,void 0,
|
||||
void 0,void 0))]}},u=function(a,f,m){h="div";t=k;p=null;b(a,y);e.defineRoutes(m,function(b,e,f){var m="function"!==typeof b.view,n=k,q=l=function(k){q===l&&(l=null,h=null!=k?k:m?"div":b,t=n,p=e,r=f,a.redraw(!0))},u=function(){q()};m&&("function"===typeof b.render&&(n=b.render.bind(b)),"function"===typeof b.onmatch&&(u=b.onmatch));u.call(b,q,e,f)},function(){e.setPath(f,null,{replace:!0})})};u.link=e.link;u.prefix=e.setPrefix;u.set=e.setPath;u.get=function(){return r};return u}(window,t.mount);t.withAttr=
|
||||
function(a,b,k){return function(e){return b.call(k||this,a in e.currentTarget?e.currentTarget[a]:e.currentTarget.getAttribute(a))}};t.render=N.render;t.redraw=J.publish;t.request=I.request;t.jsonp=I.jsonp;t.parseQueryString=K;t.buildQueryString=C;t.version="1.0.0-rc.5";"undefined"!==typeof module?module.exports=t:window.m=t};
|
||||
new function(){function n(a,h,l,b,f,k){return{tag:a,key:h,attrs:l,children:b,text:f,dom:k,domSize:void 0,state:{},events:void 0,instance:void 0,skip:!1}}function A(a){if(null==a||"string"!==typeof a&&null==a.view)throw Error("The selector must be either a string or a component.");if("string"===typeof a&&void 0===I[a]){for(var h,l,b=[],f={};h=O.exec(a);){var k=h[1],v=h[2];""===k&&""!==v?l=v:"#"===k?f.id=v:"."===k?b.push(v):"["===h[3][0]&&((k=h[6])&&(k=k.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),
|
||||
"class"===h[4]?b.push(k):f[h[4]]=k||!0)}0<b.length&&(f.className=b.join(" "));I[a]=function(a,b){var k=!1,h,d,w=a.className||a["class"],u;for(u in f)a[u]=f[u];void 0!==w&&(void 0!==a["class"]&&(a["class"]=void 0,a.className=w),void 0!==f.className&&(a.className=f.className+" "+w));for(u in a)if("key"!==u){k=!0;break}b instanceof Array&&1==b.length&&null!=b[0]&&"#"===b[0].tag?d=b[0].children:h=b;return n(l||"div",a.key,k?a:void 0,h,d,void 0)}}var p;null!=arguments[1]&&("object"!==typeof arguments[1]||
|
||||
void 0!==arguments[1].tag||arguments[1]instanceof Array)?b=1:(p=arguments[1],b=2);if(arguments.length===b+1)h=arguments[b]instanceof Array?arguments[b]:[arguments[b]];else for(h=[];b<arguments.length;b++)h.push(arguments[b]);return"string"===typeof a?I[a](p||{},n.normalizeChildren(h)):n(a,p&&p.key,p||{},n.normalizeChildren(h),void 0,void 0)}n.normalize=function(a){return a instanceof Array?n("[",void 0,void 0,n.normalizeChildren(a),void 0,void 0):null!=a&&"object"!==typeof a?n("#",void 0,void 0,a,
|
||||
void 0,void 0):a};n.normalizeChildren=function(a){for(var h=0;h<a.length;h++)a[h]=n.normalize(a[h]);return a};var O=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,I={};A.trust=function(a){null==a&&(a="");return n("<",void 0,void 0,a,void 0,void 0)};A.fragment=function(a,h){return n("[",a.key,a,n.normalizeChildren(h),void 0,void 0)};var t=function(a){function h(a,h){return function w(u){var r;try{if(!h||null==u||"object"!==typeof u&&"function"!==typeof u||"function"!==
|
||||
typeof(r=u.then))C(function(){h||0!==a.length||console.error("Possible unhandled promise rejection:",u);for(var b=0;b<a.length;b++)a[b](u);f.length=0;k.length=0;q.state=h;q.retry=function(){w(u)}});else{if(u===b)throw new TypeError("Promise can't be resolved w/ itself");l(r.bind(u))}}catch(F){p(F)}}}function l(a){function b(a){return function(b){0<d++||a(b)}}var d=0,f=b(p);try{a(b(v),f)}catch(u){f(u)}}if(!(this instanceof t))throw Error("Promise must be called with `new`");if("function"!==typeof a)throw new TypeError("executor must be a function");
|
||||
var b=this,f=[],k=[],v=h(f,!0),p=h(k,!1),q=b._instance={resolvers:f,rejectors:k},C="function"===typeof setImmediate?setImmediate:setTimeout;l(a)};t.prototype.then=function(a,h){function l(a,h,l,r){h.push(function(b){if("function"!==typeof a)l(b);else try{f(a(b))}catch(d){k&&k(d)}});"function"===typeof b.retry&&r===b.state&&b.retry()}var b=this._instance,f,k,v=new t(function(a,b){f=a;k=b});l(a,b.resolvers,f,!0);l(h,b.rejectors,k,!1);return v};t.prototype["catch"]=function(a){return this.then(null,
|
||||
a)};t.resolve=function(a){return a instanceof t?a:new t(function(h){h(a)})};t.reject=function(a){return new t(function(h,l){l(a)})};t.all=function(a){return new t(function(h,l){var b=a.length,f=0,k=[];if(0===a.length)h([]);else for(var v=0;v<a.length;v++)(function(v){function q(a){f++;k[v]=a;f===b&&h(k)}null==a[v]||"object"!==typeof a[v]&&"function"!==typeof a[v]||"function"!==typeof a[v].then?q(a[v]):a[v].then(q,l)})(v)})};t.race=function(a){return new t(function(h,l){for(var b=0;b<a.length;b++)a[b].then(h,
|
||||
l)})};"undefined"===typeof Promise&&("undefined"!==typeof window?window.Promise=t:"undefined"!==typeof global&&(global.Promise=t));var E=function(a){function h(a,b){if(b instanceof Array)for(var f=0;f<b.length;f++)h(a+"["+f+"]",b[f]);else if("[object Object]"===Object.prototype.toString.call(b))for(f in b)h(a+"["+f+"]",b[f]);else l.push(encodeURIComponent(a)+(null!=b&&""!==b?"="+encodeURIComponent(b):""))}if("[object Object]"!==Object.prototype.toString.call(a))return"";var l=[],b;for(b in a)h(b,
|
||||
a[b]);return l.join("&")},J=function(a,h){function l(){0===--r&&"function"===typeof m&&m()}function b(a){var d=a.then;a.then=function(){r++;var f=d.apply(a,arguments);f.then(l,function(a){l();throw a;});return b(f)};return a}function f(a,b){if(null==b)return a;for(var d=a.match(/:[^\/]+/gi)||[],f=0;f<d.length;f++){var h=d[f].slice(1);null!=b[h]&&(a=a.replace(d[f],b[h]),delete b[h])}return a}function k(a,b){var d=E(b);if(""!==d){var f=0>a.indexOf("?")?"?":"&";a+=f+d}return a}function v(a){try{return""!==
|
||||
a?JSON.parse(a):null}catch(w){throw Error(a);}}function p(a){return a.responseText}function q(a,b){if("function"===typeof a)if(b instanceof Array)for(var d=0;d<b.length;d++)b[d]=new a(b[d]);else return new a(b);return b}var n=0,r=0,m;return{request:function(d,l){return b(new h(function(b,h){if("string"===typeof d){var r=d;d=l||{};null==d.url&&(d.url=r)}null==d.method&&(d.method="GET");d.method=d.method.toUpperCase();r="boolean"===typeof d.useBody?d.useBody:"GET"!==d.method&&"TRACE"!==d.method;"function"!==
|
||||
typeof d.serialize&&(d.serialize="undefined"!==typeof FormData&&d.data instanceof FormData?function(a){return a}:JSON.stringify);"function"!==typeof d.deserialize&&(d.deserialize=v);"function"!==typeof d.extract&&(d.extract=p);d.url=f(d.url,d.data);r?d.data=d.serialize(d.data):d.url=k(d.url,d.data);var m=new a.XMLHttpRequest;m.open(d.method,d.url,"boolean"===typeof d.async?d.async:!0,"string"===typeof d.user?d.user:void 0,"string"===typeof d.password?d.password:void 0);d.serialize===JSON.stringify&&
|
||||
r&&m.setRequestHeader("Content-Type","application/json; charset=utf-8");d.deserialize===v&&m.setRequestHeader("Accept","application/json, text/*");d.withCredentials&&(m.withCredentials=d.withCredentials);"function"===typeof d.config&&(m=d.config(m,d)||m);m.onreadystatechange=function(){if(4===m.readyState)try{var a=d.extract!==p?d.extract(m,d):d.deserialize(d.extract(m,d));if(200<=m.status&&300>m.status||304===m.status)b(q(d.type,a));else{var f=Error(m.responseText),k;for(k in a)f[k]=a[k];h(f)}}catch(G){h(G)}};
|
||||
r&&null!=d.data?m.send(d.data):m.send()}))},jsonp:function(d){return b(new h(function(b,h){var m=d.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+n++,r=a.document.createElement("script");a[m]=function(f){r.parentNode.removeChild(r);b(q(d.type,f));delete a[m]};r.onerror=function(){r.parentNode.removeChild(r);h(Error("JSONP request failed"));delete a[m]};null==d.data&&(d.data={});d.url=f(d.url,d.data);d.data[d.callbackKey||"callback"]=m;r.src=k(d.url,d.data);a.document.documentElement.appendChild(r)}))},
|
||||
setCompletionCallback:function(a){m=a}}}(window,"undefined"!==typeof Promise?Promise:t),N=function(a){function h(g,c,a,b,d,f,h){for(;a<b;a++){var e=c[a];null!=e&&q(g,l(e,d,h),f)}}function l(g,c,a){var e=g.tag;null!=g.attrs&&t(g.attrs,g,c);if("string"===typeof e)switch(e){case "#":return g.dom=B.createTextNode(g.children);case "<":return b(g);case "[":var d=B.createDocumentFragment();null!=g.children&&(e=g.children,h(d,e,0,e.length,c,null,a));g.dom=d.firstChild;g.domSize=d.childNodes.length;return d;
|
||||
default:var f=g.tag;switch(g.tag){case "svg":a="http://www.w3.org/2000/svg";break;case "math":a="http://www.w3.org/1998/Math/MathML"}var m=(e=g.attrs)&&e.is,f=a?m?B.createElementNS(a,f,{is:m}):B.createElementNS(a,f):m?B.createElement(f,{is:m}):B.createElement(f);g.dom=f;if(null!=e)for(d in m=a,e)u(g,d,null,e[d],m);null!=g.attrs&&null!=g.attrs.contenteditable?C(g):(null!=g.text&&(""!==g.text?f.textContent=g.text:g.children=[n("#",void 0,void 0,g.text,void 0,void 0)]),null!=g.children&&(d=g.children,
|
||||
h(f,d,0,d.length,c,null,a),c=g.attrs,"select"===g.tag&&null!=c&&("value"in c&&u(g,"value",null,c.value,void 0),"selectedIndex"in c&&u(g,"selectedIndex",null,c.selectedIndex,void 0))));return f}else{g.state||(g.state={});E(g.state,g.tag);d=g.tag.view;if(null!=d.reentrantLock)g=G;else if(d.reentrantLock=!0,t(g.tag,g,c),g.instance=n.normalize(d.call(g.state,g)),d.reentrantLock=null,null!=g.instance){if(g.instance===g)throw Error("A view cannot return the vnode it received as arguments");c=l(g.instance,
|
||||
c,a);g.dom=g.instance.dom;g.domSize=null!=g.dom?g.instance.domSize:0;g=c}else g.domSize=0,g=G;return g}}function b(g){var c={caption:"table",thead:"table",tbody:"table",tfoot:"table",tr:"tbody",th:"tr",td:"tr",colgroup:"table",col:"colgroup"}[(g.children.match(/^\s*?<(\w+)/im)||[])[1]]||"div",c=B.createElement(c);c.innerHTML=g.children;g.dom=c.firstChild;g.domSize=c.childNodes.length;g=B.createDocumentFragment();for(var a;a=c.firstChild;)g.appendChild(a);return g}function f(g,c,a,d,b,f){if(c!==a&&
|
||||
(null!=c||null!=a))if(null==c)h(g,a,0,a.length,d,b,void 0);else if(null==a)r(c,0,c.length,a);else if(c.length===a.length&&null!=a[0]&&null==a[0].key)for(var e=0;e<c.length;e++)c[e]===a[e]||null==c[e]&&null==a[e]||(null==c[e]?q(g,l(a[e],d,f),p(c,e+1,b)):null==a[e]?r(c,e,e+1,a):k(g,c[e],a[e],d,p(c,e+1,b),!1,f));else{a:{if(null!=c.pool&&Math.abs(c.pool.length-a.length)<=Math.abs(c.length-a.length)&&(e=a[0]&&a[0].children&&a[0].children.length||0,Math.abs((c.pool[0]&&c.pool[0].children&&c.pool[0].children.length||
|
||||
0)-e)<=Math.abs((c[0]&&c[0].children&&c[0].children.length||0)-e))){e=!0;break a}e=!1}e&&(c=c.concat(c.pool));for(var m=0,y=0,z=c.length-1,u=a.length-1,w;z>=m&&u>=y;){var x=c[m],n=a[y];if(x!==n||e)if(null==x)m++;else if(null==n)y++;else if(x.key===n.key)m++,y++,k(g,x,n,d,p(c,m,b),e,f),e&&x.tag===n.tag&&q(g,v(x),b);else if(x=c[z],x!==n||e)if(null==x)z--;else if(null==n)y++;else if(x.key===n.key)k(g,x,n,d,p(c,z+1,b),e,f),(e||y<u)&&q(g,v(x),p(c,m,b)),z--,y++;else break;else z--,y++;else m++,y++}for(;z>=
|
||||
m&&u>=y;){x=c[z];n=a[u];if(x!==n||e)if(null==x)z--;else{if(null!=n)if(x.key===n.key)k(g,x,n,d,p(c,z+1,b),e,f),e&&x.tag===n.tag&&q(g,v(x),b),null!=x.dom&&(b=x.dom),z--;else{if(!w){w=c;var x=z,D={},t;for(t=0;t<x;t++){var C=w[t];null!=C&&(C=C.key,null!=C&&(D[C]=t))}w=D}null!=n&&(x=w[n.key],null!=x?(D=c[x],k(g,D,n,d,p(c,z+1,b),e,f),q(g,v(D),b),c[x].skip=!0,null!=D.dom&&(b=D.dom)):(n=l(n,d,void 0),q(g,n,b),b=n))}u--}else z--,u--;if(u<y)break}h(g,a,y,u+1,d,b,f);r(c,m,z+1,a)}}function k(a,c,e,h,m,r,w){var g=
|
||||
c.tag;if(g===e.tag){e.state=c.state;e.events=c.events;var y;var z;null!=e.attrs&&"function"===typeof e.attrs.onbeforeupdate&&(y=e.attrs.onbeforeupdate.call(e.state,e,c));"string"!==typeof e.tag&&"function"===typeof e.tag.onbeforeupdate&&(z=e.tag.onbeforeupdate.call(e.state,e,c));void 0===y&&void 0===z||y||z?y=!1:(e.dom=c.dom,e.domSize=c.domSize,e.instance=c.instance,y=!0);if(!y)if(null!=e.attrs&&A(e.attrs,e,h,r),"string"===typeof g)switch(g){case "#":c.children.toString()!==e.children.toString()&&
|
||||
(c.dom.nodeValue=e.children);e.dom=c.dom;break;case "<":c.children!==e.children?(v(c),q(a,b(e),m)):(e.dom=c.dom,e.domSize=c.domSize);break;case "[":f(a,c.children,e.children,h,m,w);c=0;h=e.children;e.dom=null;if(null!=h){for(var p=0;p<h.length;p++)a=h[p],null!=a&&null!=a.dom&&(null==e.dom&&(e.dom=a.dom),c+=a.domSize||1);1!==c&&(e.domSize=c)}break;default:a=w;m=e.dom=c.dom;switch(e.tag){case "svg":a="http://www.w3.org/2000/svg";break;case "math":a="http://www.w3.org/1998/Math/MathML"}"textarea"===
|
||||
e.tag&&(null==e.attrs&&(e.attrs={}),null!=e.text&&(e.attrs.value=e.text,e.text=void 0));r=c.attrs;w=e.attrs;g=a;if(null!=w)for(p in w)u(e,p,r&&r[p],w[p],g);if(null!=r)for(p in r)null!=w&&p in w||("className"===p&&(p="class"),"o"!==p[0]||"n"!==p[1]||M(p)?"key"!==p&&e.dom.removeAttribute(p):F(e,p,void 0));null!=e.attrs&&null!=e.attrs.contenteditable?C(e):null!=c.text&&null!=e.text&&""!==e.text?c.text.toString()!==e.text.toString()&&(c.dom.firstChild.nodeValue=e.text):(null!=c.text&&(c.children=[n("#",
|
||||
void 0,void 0,c.text,void 0,c.dom.firstChild)]),null!=e.text&&(e.children=[n("#",void 0,void 0,e.text,void 0,void 0)]),f(m,c.children,e.children,h,null,a))}else e.instance=n.normalize(e.tag.view.call(e.state,e)),A(e.tag,e,h,r),null!=e.instance?(null==c.instance?q(a,l(e.instance,h,w),m):k(a,c.instance,e.instance,h,m,r,w),e.dom=e.instance.dom,e.domSize=e.instance.domSize):null!=c.instance?(d(c.instance,null),e.dom=void 0,e.domSize=0):(e.dom=c.dom,e.domSize=c.domSize)}else d(c,null),q(a,l(e,h,w),m)}
|
||||
function v(a){var g=a.domSize;if(null!=g||null==a.dom){var e=B.createDocumentFragment();if(0<g){for(a=a.dom;--g;)e.appendChild(a.nextSibling);e.insertBefore(a,e.firstChild)}return e}return a.dom}function p(a,c,e){for(;c<a.length;c++)if(null!=a[c]&&null!=a[c].dom)return a[c].dom;return e}function q(a,c,e){e&&e.parentNode?a.insertBefore(c,e):a.appendChild(c)}function C(a){var c=a.children;if(null!=c&&1===c.length&&"<"===c[0].tag)c=c[0].children,a.dom.innerHTML!==c&&(a.dom.innerHTML=c);else if(null!=
|
||||
c||null!=a.text)throw Error("Child node of a contenteditable must be trusted");}function r(a,c,e,b){for(;c<e;c++){var g=a[c];null!=g&&(g.skip?g.skip=!1:d(g,b))}}function m(a){var c=!1;return function(){c||(c=!0,a())}}function d(a,c){function g(){if(++d===b&&(w(a),a.dom)){var g=a.domSize||1;if(1<g)for(var e=a.dom;--g;){var f=e.nextSibling,h=f.parentNode;null!=h&&h.removeChild(f)}g=a.dom;e=g.parentNode;null!=e&&e.removeChild(g);if(g=null!=c&&null==a.domSize)g=a.attrs,g=!(null!=g&&(g.oncreate||g.onupdate||
|
||||
g.onbeforeremove||g.onremove));g&&"string"===typeof a.tag&&(c.pool?c.pool.push(a):c.pool=[a])}}var b=1,d=0;a.attrs&&a.attrs.onbeforeremove&&(b++,a.attrs.onbeforeremove.call(a.state,a,m(g)));"string"!==typeof a.tag&&a.tag.onbeforeremove&&(b++,a.tag.onbeforeremove.call(a.state,a,m(g)));g()}function w(a){a.attrs&&a.attrs.onremove&&a.attrs.onremove.call(a.state,a);"string"!==typeof a.tag&&a.tag.onremove&&a.tag.onremove.call(a.state,a);if(null!=a.instance)w(a.instance);else if(a=a.children,a instanceof
|
||||
Array)for(var c=0;c<a.length;c++){var g=a[c];null!=g&&w(g)}}function u(a,c,e,b,d){var g=a.dom;if("key"!==c&&(e!==b||"value"===c||"checked"===c||"selectedIndex"===c||"selected"===c&&a.dom===B.activeElement||"object"===typeof b)&&"undefined"!==typeof b&&!M(c)){var f=c.indexOf(":");if(-1<f&&"xlink"===c.substr(0,f))g.setAttributeNS("http://www.w3.org/1999/xlink",c.slice(f+1),b);else if("o"===c[0]&&"n"===c[1]&&"function"===typeof b)F(a,c,b);else if("style"===c)if(a=e,a===b&&(g.style.cssText="",a=null),
|
||||
null==b)g.style.cssText="";else if("string"===typeof b)g.style.cssText=b;else{"string"===typeof a&&(g.style.cssText="");for(var h in b)g.style[h]=b[h];if(null!=a&&"string"!==typeof a)for(h in a)h in b||(g.style[h]="")}else c in g&&"href"!==c&&"list"!==c&&"form"!==c&&"width"!==c&&"height"!==c&&void 0===d?"input"===a.tag&&"value"===c&&a.dom.value===b&&a.dom===B.activeElement||"select"===a.tag&&"value"===c&&a.dom.value===b&&a.dom===B.activeElement||"option"===a.tag&&"value"===c&&a.dom.value===b||(g[c]=
|
||||
b):"boolean"===typeof b?b?g.setAttribute(c,""):g.removeAttribute(c):g.setAttribute("className"===c?"class":c,b)}}function M(a){return"oninit"===a||"oncreate"===a||"onupdate"===a||"onremove"===a||"onbeforeremove"===a||"onbeforeupdate"===a}function F(a,c,b){var e=a.dom,g=function(a){var c=b.call(e,a);"function"===typeof K&&K.call(e,a);return c};if(c in e)e[c]="function"===typeof b?g:null;else{var d=c.slice(2);void 0===a.events&&(a.events={});null!=a.events[c]&&e.removeEventListener(d,a.events[c],!1);
|
||||
"function"===typeof b&&(a.events[c]=g,e.addEventListener(d,a.events[c],!1))}}function t(a,c,b){"function"===typeof a.oninit&&a.oninit.call(c.state,c);"function"===typeof a.oncreate&&b.push(a.oncreate.bind(c.state,c))}function A(a,c,b,d){d?t(a,c,b):"function"===typeof a.onupdate&&b.push(a.onupdate.bind(c.state,c))}function E(a,c){Object.keys(c).forEach(function(b){a[b]=c[b]})}var B=a.document,G=B.createDocumentFragment(),K;return{render:function(a,c){if(!a)throw Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");
|
||||
var b=[],d=B.activeElement;null==a.vnodes&&(a.textContent="");c instanceof Array||(c=[c]);f(a,a.vnodes,n.normalizeChildren(c),b,null,void 0);a.vnodes=c;for(var g=0;g<b.length;g++)b[g]();B.activeElement!==d&&d.focus()},setEventCallback:function(a){return K=a}}},H=function(a){function h(a){a=b.indexOf(a);-1<a&&b.splice(a,2)}function l(){for(var a=1;a<b.length;a+=2)b[a]()}a=N(a);a.setEventCallback(function(a){!1!==a.redraw&&l()});var b=[];return{subscribe:function(a,k){h(a);b.push(a,k)},unsubscribe:h,
|
||||
redraw:l,render:a.render}}(window),P=N(window);J.setCompletionCallback(H.redraw);A.mount=function(a){function h(a){var b=0,f=null,h="function"===typeof requestAnimationFrame?requestAnimationFrame:setTimeout;return function(){var k=Date.now();0===b||16<=k-b?(b=k,a()):null===f&&(f=h(function(){f=null;a();b=Date.now()},16-(k-b)))}}return function(l,b){if(null===b)a.render(l,[]),a.unsubscribe(l);else{if(null==b.view)throw Error("m.mount(element, component) expects a component, not a vnode");var f=h(function(){a.render(l,
|
||||
n(b))});a.subscribe(l,f);f()}}}(H);var L=function(a){if(""===a||null==a)return{};"?"===a.charAt(0)&&(a=a.slice(1));a=a.split("&");for(var h={},l={},b=0;b<a.length;b++){var f=a[b].split("="),k=decodeURIComponent(f[0]),f=2===f.length?decodeURIComponent(f[1]):"";"true"===f?f=!0:"false"===f&&(f=!1);var n=k.split(/\]\[?|\[/),p=h;-1<k.indexOf("[")&&n.pop();for(var q=0;q<n.length;q++){var k=n[q],t=n[q+1],t=""==t||!isNaN(parseInt(t,10)),r=q===n.length-1;""===k&&(k=n.slice(0,q).join(),null==l[k]&&(l[k]=0),
|
||||
k=l[k]++);null==p[k]&&(p[k]=r?f:t?[]:{});p=p[k]}}return h},Q=function(a){function h(b){var f=a.location[b].replace(/(?:%[a-f89][a-f0-9])+/gim,decodeURIComponent);"pathname"===b&&"/"!==f[0]&&(f="/"+f);return f}function l(a){return function(b){null==t&&(t=p(function(){t=null;a(b)}))}}function b(a,b,d){var f=a.indexOf("?"),h=a.indexOf("#"),m=-1<f?f:-1<h?h:a.length;if(-1<f){var f=L(a.slice(f+1,-1<h?h:a.length)),k;for(k in f)b[k]=f[k]}if(-1<h)for(k in b=L(a.slice(h+1)),b)d[k]=b[k];return a.slice(0,m)}
|
||||
function f(){switch(q.charAt(0)){case "#":return h("hash").slice(q.length);case "?":return h("search").slice(q.length)+h("hash");default:return h("pathname").slice(q.length)+h("search")+h("hash")}}function k(f,h,d){var m={},k={};f=b(f,m,k);if(null!=h){for(var l in h)m[l]=h[l];f=f.replace(/:([^\/]+)/g,function(a,b){delete m[b];return h[b]})}(l=E(m))&&(f+="?"+l);(k=E(k))&&(f+="#"+k);n?(d&&d.replace?a.history.replaceState(null,null,q+f):a.history.pushState(null,null,q+f),a.onpopstate(!0)):a.location.href=
|
||||
q+f}var n="function"===typeof a.history.pushState,p="function"===typeof setImmediate?setImmediate:setTimeout,q="#!",t;return{setPrefix:function(a){q=a},getPath:f,setPath:k,defineRoutes:function(h,m,d){function k(a){var k=f(),l={},n=b(k,l,l),r;for(r in h){var p=new RegExp("^"+r.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$");if(p.test(n)){n.replace(p,function(){for(var b=r.match(/:[^\/]+/g)||[],d=[].slice.call(arguments,1,-2),f=0;f<b.length;f++)l[b[f].replace(/:|\./g,"")]=
|
||||
decodeURIComponent(d[f]);m(h[r],l,k,r,!!a)});return}}d(k,l)}n?a.onpopstate=l(k):"#"===q.charAt(0)&&(a.onhashchange=k);k(!0);return function(){k(!1)}},link:function(a){a.dom.setAttribute("href",q+a.attrs.href);a.dom.onclick=function(a){a.ctrlKey||a.metaKey||a.shiftKey||2===a.which||(a.preventDefault(),a.redraw=!1,a=this.getAttribute("href"),0===a.indexOf(q)&&(a=a.slice(q.length)),k(a,void 0,void 0))}}}};A.route=function(a,h){var l=Q(a),b=function(a){return a},f={render:b,component:null,path:null,resolve:null},
|
||||
k=function(a,k,q){if(null==a)throw Error("Ensure the DOM element that was passed to `m.route` is not undefined");var p=function(k,m,d,l){f.render=k.render||b;f.component=m;f.path=l;f.resolve=null;h.render(a,f.render(n(m,void 0,d)))};q=l.defineRoutes(q,function(a,b,d,h,k){a.view?p({},a,b,d):a.onmatch?!1===k&&f.path===d||null!=f.resolve?p(f,f.component,b):(f.resolve=function(f){p(a,f,b,d)},a.onmatch(function(a){f.path!==d&&null!=f.resolve&&f.resolve(a)},b,d)):p(a,"div",b,d)},function(){l.setPath(k)});
|
||||
h.subscribe(a,q)};k.set=l.setPath;k.get=function(){return f.path};k.prefix=l.setPrefix;k.link=l.link;return k}(window,H);A.withAttr=function(a,h,l){return function(b){return h.call(l||this,a in b.currentTarget?b.currentTarget[a]:b.currentTarget.getAttribute(a))}};A.render=P.render;A.redraw=H.redraw;A.request=J.request;A.jsonp=J.jsonp;A.parseQueryString=L;A.buildQueryString=E;A.version="1.0.0-rc.6";"undefined"!==typeof module?module.exports=A:window.m=A};
|
||||
3
mount.js
3
mount.js
|
|
@ -1,4 +1,3 @@
|
|||
var renderService = require("./render")
|
||||
var redrawService = require("./redraw")
|
||||
|
||||
module.exports = require("./api/mount")(renderService, redrawService)
|
||||
module.exports = require("./api/mount")(redrawService)
|
||||
|
|
@ -1 +1 @@
|
|||
module.exports = require("./api/pubsub")()
|
||||
module.exports = require("./api/redraw")(window)
|
||||
4
route.js
4
route.js
|
|
@ -1,3 +1,3 @@
|
|||
var mount = require("./mount")
|
||||
var redrawService = require("./redraw")
|
||||
|
||||
module.exports = require("./api/router")(window, mount)
|
||||
module.exports = require("./api/router")(window, redrawService)
|
||||
|
|
@ -18,11 +18,11 @@ module.exports = function($window) {
|
|||
|
||||
var asyncId
|
||||
function debounceAsync(f) {
|
||||
return function() {
|
||||
return function(e) {
|
||||
if (asyncId != null) return
|
||||
asyncId = callAsync(function() {
|
||||
asyncId = null
|
||||
f()
|
||||
f(e)
|
||||
})
|
||||
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ module.exports = function($window) {
|
|||
if (supportsPushState) {
|
||||
if (options && options.replace) $window.history.replaceState(null, null, prefix + path)
|
||||
else $window.history.pushState(null, null, prefix + path)
|
||||
$window.onpopstate()
|
||||
$window.onpopstate(true)
|
||||
}
|
||||
else $window.location.href = prefix + path
|
||||
}
|
||||
|
|
@ -81,9 +81,9 @@ module.exports = function($window) {
|
|||
function defineRoutes(routes, resolve, reject) {
|
||||
if (supportsPushState) $window.onpopstate = debounceAsync(resolveRoute)
|
||||
else if (prefix.charAt(0) === "#") $window.onhashchange = resolveRoute
|
||||
resolveRoute()
|
||||
resolveRoute(true)
|
||||
|
||||
function resolveRoute() {
|
||||
function resolveRoute(isRouteChange) {
|
||||
var path = getPath()
|
||||
var params = {}
|
||||
var pathname = parsePath(path, params, params)
|
||||
|
|
@ -98,7 +98,7 @@ module.exports = function($window) {
|
|||
for (var i = 0; i < keys.length; i++) {
|
||||
params[keys[i].replace(/:|\./g, "")] = decodeURIComponent(values[i])
|
||||
}
|
||||
resolve(routes[route], params, path, route)
|
||||
resolve(routes[route], params, path, route, !!isRouteChange)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
|
@ -106,7 +106,7 @@ module.exports = function($window) {
|
|||
|
||||
reject(path, params)
|
||||
}
|
||||
return resolveRoute
|
||||
return function() {resolveRoute(false)}
|
||||
}
|
||||
|
||||
function link(vnode) {
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ o.spec("Router.defineRoutes", function() {
|
|||
|
||||
callAsync(function() {
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/test", "/test"])
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/test", "/test", true])
|
||||
o(onFail.callCount).equals(0)
|
||||
|
||||
done()
|
||||
|
|
@ -49,7 +49,7 @@ o.spec("Router.defineRoutes", function() {
|
|||
|
||||
callAsync(function() {
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 2}, {"ö": "ö"}, "/ö?ö=ö#ö=ö", "/ö"])
|
||||
o(onRouteChange.args).deepEquals([{data: 2}, {"ö": "ö"}, "/ö?ö=ö#ö=ö", "/ö", true])
|
||||
o(onFail.callCount).equals(0)
|
||||
|
||||
done()
|
||||
|
|
@ -62,7 +62,7 @@ o.spec("Router.defineRoutes", function() {
|
|||
|
||||
callAsync(function() {
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 2}, {"ö": "ö"}, "/ö?ö=ö#ö=ö", "/ö"])
|
||||
o(onRouteChange.args).deepEquals([{data: 2}, {"ö": "ö"}, "/ö?ö=ö#ö=ö", "/ö", true])
|
||||
o(onFail.callCount).equals(0)
|
||||
|
||||
done()
|
||||
|
|
@ -79,7 +79,7 @@ o.spec("Router.defineRoutes", function() {
|
|||
|
||||
callAsync(function() {
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/test", "/test"])
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/test", "/test", true])
|
||||
o(onFail.callCount).equals(0)
|
||||
|
||||
done()
|
||||
|
|
@ -92,7 +92,7 @@ o.spec("Router.defineRoutes", function() {
|
|||
|
||||
callAsync(function() {
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "x"}, "/test/x", "/test/:a"])
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "x"}, "/test/x", "/test/:a", true])
|
||||
o(onFail.callCount).equals(0)
|
||||
|
||||
done()
|
||||
|
|
@ -105,7 +105,7 @@ o.spec("Router.defineRoutes", function() {
|
|||
|
||||
callAsync(function() {
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "x", b: "y"}, "/test/x/y", "/test/:a/:b"])
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "x", b: "y"}, "/test/x/y", "/test/:a/:b", true])
|
||||
o(onFail.callCount).equals(0)
|
||||
|
||||
done()
|
||||
|
|
@ -118,7 +118,7 @@ o.spec("Router.defineRoutes", function() {
|
|||
|
||||
callAsync(function() {
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "x/y"}, "/test/x/y", "/test/:a..."])
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "x/y"}, "/test/x/y", "/test/:a...", true])
|
||||
o(onFail.callCount).equals(0)
|
||||
|
||||
done()
|
||||
|
|
@ -131,7 +131,7 @@ o.spec("Router.defineRoutes", function() {
|
|||
|
||||
callAsync(function() {
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "b", c: "d"}, "/test?a=b&c=d", "/test"])
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "b", c: "d"}, "/test?a=b&c=d", "/test", true])
|
||||
o(onFail.callCount).equals(0)
|
||||
|
||||
done()
|
||||
|
|
@ -144,7 +144,7 @@ o.spec("Router.defineRoutes", function() {
|
|||
|
||||
callAsync(function() {
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "b", c: "d"}, "/test#a=b&c=d", "/test"])
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "b", c: "d"}, "/test#a=b&c=d", "/test", true])
|
||||
o(onFail.callCount).equals(0)
|
||||
|
||||
done()
|
||||
|
|
@ -157,7 +157,7 @@ o.spec("Router.defineRoutes", function() {
|
|||
|
||||
callAsync(function() {
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "b", c: "d"}, "/test?a=b#c=d", "/test"])
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "b", c: "d"}, "/test?a=b#c=d", "/test", true])
|
||||
o(onFail.callCount).equals(0)
|
||||
|
||||
done()
|
||||
|
|
@ -194,7 +194,7 @@ o.spec("Router.defineRoutes", function() {
|
|||
|
||||
callAsync(function() {
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/z/y/x", "/z/y/x"])
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/z/y/x", "/z/y/x", true])
|
||||
|
||||
done()
|
||||
})
|
||||
|
|
@ -206,7 +206,7 @@ o.spec("Router.defineRoutes", function() {
|
|||
|
||||
callAsync(function() {
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 2}, {a: "z/y/x"}, "/z/y/x", "/:a..."])
|
||||
o(onRouteChange.args).deepEquals([{data: 2}, {a: "z/y/x"}, "/z/y/x", "/:a...", true])
|
||||
|
||||
done()
|
||||
})
|
||||
|
|
@ -222,7 +222,7 @@ o.spec("Router.defineRoutes", function() {
|
|||
|
||||
callAsync(function() {
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/z/y/x", "/z/y/x"])
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/z/y/x", "/z/y/x", true])
|
||||
|
||||
done()
|
||||
})
|
||||
|
|
@ -238,7 +238,7 @@ o.spec("Router.defineRoutes", function() {
|
|||
|
||||
callAsync(function() {
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 2}, {a: "z/y/x"}, "/z/y/x", "/:a..."])
|
||||
o(onRouteChange.args).deepEquals([{data: 2}, {a: "z/y/x"}, "/z/y/x", "/:a...", true])
|
||||
|
||||
done()
|
||||
})
|
||||
|
|
@ -253,7 +253,7 @@ o.spec("Router.defineRoutes", function() {
|
|||
|
||||
callAsync(function() {
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/z/y/x", "/z/y/x"])
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/z/y/x", "/z/y/x", true])
|
||||
|
||||
done()
|
||||
})
|
||||
|
|
@ -268,7 +268,7 @@ o.spec("Router.defineRoutes", function() {
|
|||
|
||||
callAsync(function() {
|
||||
o(onRouteChange.callCount).equals(1)
|
||||
o(onRouteChange.args).deepEquals([{data: 2}, {a: "z/y/x"}, "/z/y/x", "/:a..."])
|
||||
o(onRouteChange.args).deepEquals([{data: 2}, {a: "z/y/x"}, "/z/y/x", "/:a...", true])
|
||||
|
||||
done()
|
||||
})
|
||||
|
|
@ -291,7 +291,7 @@ o.spec("Router.defineRoutes", function() {
|
|||
replay()
|
||||
|
||||
o(onRouteChange.callCount).equals(2)
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/test", "/test"])
|
||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/test", "/test", false])
|
||||
o(onFail.callCount).equals(0)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue