clear diff cache when routing
This commit is contained in:
parent
07c4e0bdd2
commit
b1275cb778
3 changed files with 37 additions and 5 deletions
|
|
@ -1,6 +1,6 @@
|
|||
module.exports = function(grunt) {
|
||||
|
||||
var version = "0.1.17"
|
||||
var version = "0.1.18"
|
||||
|
||||
var inputFolder = "./docs"
|
||||
var tempFolder = "./temp"
|
||||
|
|
|
|||
12
mithril.js
12
mithril.js
|
|
@ -297,13 +297,13 @@ Mithril = m = new function app(window) {
|
|||
m.render = function(root, cell) {
|
||||
var configs = []
|
||||
if (!root) throw new Error("Please ensure the DOM element exists before rendering a template into it.")
|
||||
var id = getCellCacheId(root)
|
||||
var id = getCellCacheKey(root)
|
||||
var node = root == window.document || root == window.document.documentElement ? documentNode : root
|
||||
if (cellCache[id] === undefined) clear(node.childNodes)
|
||||
cellCache[id] = build(node, null, undefined, undefined, cell, cellCache[id], false, 0, null, undefined, configs)
|
||||
for (var i = 0; i < configs.length; i++) configs[i]()
|
||||
}
|
||||
function getCellCacheId(element) {
|
||||
function getCellCacheKey(element) {
|
||||
var index = nodeCache.indexOf(element)
|
||||
return index < 0 ? nodeCache.push(element) - 1 : index
|
||||
}
|
||||
|
|
@ -433,7 +433,9 @@ Mithril = m = new function app(window) {
|
|||
|
||||
for (var route in router) {
|
||||
if (route == path) {
|
||||
clear(root.childNodes, cellCache[getCellCacheId(root)])
|
||||
var cacheKey = getCellCacheKey(root)
|
||||
clear(root.childNodes, cellCache[cacheKey])
|
||||
cellCache[cacheKey] = undefined
|
||||
m.module(root, router[route])
|
||||
return true
|
||||
}
|
||||
|
|
@ -441,7 +443,9 @@ Mithril = m = new function app(window) {
|
|||
var matcher = new RegExp("^" + route.replace(/:[^\/]+?\.{3}/g, "(.*?)").replace(/:[^\/]+/g, "([^\\/]+)") + "\/?$")
|
||||
|
||||
if (matcher.test(path)) {
|
||||
clear(root.childNodes, cellCache[getCellCacheId(root)])
|
||||
var cacheKey = getCellCacheKey(root)
|
||||
clear(root.childNodes, cellCache[cacheKey])
|
||||
cellCache[cacheKey] = undefined
|
||||
path.replace(matcher, function() {
|
||||
var keys = route.match(/:[^\/]+/g) || []
|
||||
var values = [].slice.call(arguments, 1, -2)
|
||||
|
|
|
|||
|
|
@ -1137,6 +1137,34 @@ function testMithril(mock) {
|
|||
mock.performance.$elapse(50) //teardown
|
||||
return unloaded == 1
|
||||
})
|
||||
test(function() {
|
||||
mock.performance.$elapse(50) //setup
|
||||
mock.location.search = "?"
|
||||
|
||||
var root = mock.document.createElement("div")
|
||||
m.route.mode = "search"
|
||||
m.route(root, "/foo", {
|
||||
"/foo": {
|
||||
controller: function() {},
|
||||
view: function() {
|
||||
return m("div", "foo");
|
||||
}
|
||||
},
|
||||
"/bar": {
|
||||
controller: function() {},
|
||||
view: function() {
|
||||
return m("div", "bar");
|
||||
}
|
||||
},
|
||||
})
|
||||
mock.performance.$elapse(50)
|
||||
var foo = root.childNodes[0].childNodes[0].nodeValue;
|
||||
m.route("/bar")
|
||||
mock.performance.$elapse(50) //teardown
|
||||
console.log(root.childNodes)
|
||||
var bar = root.childNodes[0].childNodes[0].nodeValue;
|
||||
return (foo === "foo" && bar === "bar")
|
||||
})
|
||||
//end m.route
|
||||
|
||||
//m.prop
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue