Do some local style modifications and profile.

1. Do some temporary style modifications to help make the code more readable
   for profiling (with help from ESLint).
2. Profile the code, and optimize accordingly.
This commit is contained in:
impinball 2015-07-09 16:14:08 -04:00
parent 83a30a4d3c
commit 9ae592ee4d
12 changed files with 4426 additions and 2695 deletions

View file

@ -1,3 +1,4 @@
/* eslint-disable no-extend-native, strict */
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(item) {
for (var i = 0; i < this.length; i++) {
@ -31,9 +32,11 @@ if (!Object.keys) {
return keys
}
}
/* eslint-enable no-extend-native, strict */
var mock = {}
mock.window = (function() {
"use strict"
var window = {}
window.document = {}
window.document.childNodes = []
@ -55,11 +58,12 @@ mock.window = (function() {
else this.childNodes.splice(referenceIndex, 0, node)
},
insertAdjacentHTML: function(position, html) {
//todo: accept markup
if (position == "beforebegin") {
this.parentNode.insertBefore(window.document.createTextNode(html), this)
}
else if (position == "beforeend") {
// todo: accept markup
if (position === "beforebegin") {
this.parentNode.insertBefore(
window.document.createTextNode(html),
this)
} else if (position === "beforeend") {
this.appendChild(window.document.createTextNode(html))
}
},
@ -70,7 +74,7 @@ mock.window = (function() {
this.namespaceURI = namespace
this[name] = value.toString()
},
getAttribute: function(name, value) {
getAttribute: function(name) {
return this[name]
},
addEventListener: function () {},
@ -104,23 +108,25 @@ mock.window = (function() {
this.childNodes.splice(index, 1)
child.parentNode = null
}
//getElementsByTagName is only used by JSONP tests, it's not required by Mithril
// getElementsByTagName is only used by JSONP tests, it's not required by
// Mithril
window.document.getElementsByTagName = function(name){
name = name.toLowerCase();
var out = [];
name = name.toLowerCase()
var out = []
var traverse = function(node){
if(node.childNodes && node.childNodes.length > 0){
node.childNodes.map(function(curr){
if(curr.nodeName.toLowerCase() === name)
out.push(curr);
traverse(curr);
});
if (curr.nodeName.toLowerCase() === name) {
out.push(curr)
}
traverse(curr)
})
}
};
}
traverse(window.document);
return out;
traverse(window.document)
return out
}
window.scrollTo = function() {}
window.cancelAnimationFrame = function() {}
@ -156,15 +162,17 @@ mock.window = (function() {
request.$instances = []
return request
}())
window.location = {search: "", pathname: "", hash: ""},
window.location = {search: "", pathname: "", hash: ""}
window.history = {}
window.history.$$length = 0
window.history.pushState = function(data, title, url) {
window.history.$$length++
window.location.pathname = window.location.search = window.location.hash = url
},
window.location.pathname = window.location.search =
window.location.hash = url
}
window.history.replaceState = function(data, title, url) {
window.location.pathname = window.location.search = window.location.hash = url
window.location.pathname = window.location.search =
window.location.hash = url
}
return window
}())
}())