add ability to abort from controller::onunload
This commit is contained in:
parent
81f3367be9
commit
b486e53b4b
3 changed files with 31 additions and 7 deletions
20
mithril.js
20
mithril.js
|
|
@ -297,14 +297,22 @@ Mithril = m = new function app(window) {
|
|||
|
||||
var roots = [], modules = [], controllers = [], now = 0, lastRedraw = 0, lastRedrawId = 0, computePostRedrawHook = null
|
||||
m.module = function(root, module) {
|
||||
m.startComputation()
|
||||
var index = roots.indexOf(root)
|
||||
if (index < 0) index = roots.length
|
||||
roots[index] = root
|
||||
modules[index] = module
|
||||
if (controllers[index] && typeof controllers[index].onunload == "function") controllers[index].onunload()
|
||||
controllers[index] = new module.controller
|
||||
m.endComputation()
|
||||
var isPrevented = false
|
||||
if (controllers[index] && typeof controllers[index].onunload == "function") {
|
||||
var event = {
|
||||
preventDefault: function() {isPrevented = true}
|
||||
}
|
||||
controllers[index].onunload(event)
|
||||
}
|
||||
if (!isPrevented) {
|
||||
m.startComputation()
|
||||
roots[index] = root
|
||||
modules[index] = module
|
||||
controllers[index] = new module.controller
|
||||
m.endComputation()
|
||||
}
|
||||
}
|
||||
m.redraw = function() {
|
||||
now = window.performance && window.performance.now ? window.performance.now() : new window.Date().getTime()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue