From 6b344003e81e0a89cfad4c16feb32704f93e09e6 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Sat, 2 Aug 2014 16:08:34 -0400 Subject: [PATCH] fix array type checks --- Gruntfile.js | 2 +- mithril.js | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 812393da..c0ad76c5 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,7 +1,7 @@ module.exports = function(grunt) { _ = require('lodash'); - var version = "0.1.19" + var version = "0.1.20" var inputFolder = "./docs" var tempFolder = "./temp" diff --git a/mithril.js b/mithril.js index f36a54bb..688c187b 100644 --- a/mithril.js +++ b/mithril.js @@ -106,7 +106,7 @@ Mithril = m = new function app(window) { var item = build(parentElement, parentTag, cached, index, data[i], cached[cacheCount], shouldReattach, index + subArrayCount || subArrayCount, editable, namespace, configs) if (item === undefined) continue if (!item.nodes.intact) intact = false - var isArray = item instanceof Array + var isArray = type.call(item) == "[object Array]" subArrayCount += isArray ? item.length : 1 cached[cacheCount++] = item } @@ -246,7 +246,7 @@ Mithril = m = new function app(window) { function unload(cached) { if (cached.configContext && typeof cached.configContext.onunload == "function") cached.configContext.onunload() if (cached.children) { - if (cached.children instanceof Array) for (var i = 0; i < cached.children.length; i++) unload(cached.children[i]) + if (type.call(cached.children) == "[object Array]") for (var i = 0; i < cached.children.length; i++) unload(cached.children[i]) else if (cached.children.tag) unload(cached.children) } } @@ -274,7 +274,7 @@ Mithril = m = new function app(window) { var flattened = [] for (var i = 0; i < data.length; i++) { var item = data[i] - if (item instanceof Array) flattened.push.apply(flattened, flatten(item)) + if (type.call(item) == "[object Array]") flattened.push.apply(flattened, flatten(item)) else flattened.push(item) } return flattened @@ -332,7 +332,7 @@ Mithril = m = new function app(window) { return value } - var roots = [], modules = [], controllers = [], lastRedrawId = 0, computePostRedrawHook = null + var roots = [], modules = [], controllers = [], lastRedrawId = 0, computePostRedrawHook = null, prevented = false m.module = function(root, module) { var index = roots.indexOf(root) if (index < 0) index = roots.length @@ -352,6 +352,11 @@ Mithril = m = new function app(window) { } } m.redraw = function() { + if (prevented) { + prevented = false + return + } + var cancel = window.cancelAnimationFrame || window.clearTimeout var defer = window.requestAnimationFrame || window.setTimeout if (lastRedrawId) { @@ -363,6 +368,7 @@ Mithril = m = new function app(window) { lastRedrawId = defer(function() {lastRedrawId = null}, 0) } } + m.preventRedraw = function() {prevented = true} function redraw() { for (var i = 0; i < roots.length; i++) { if (controllers[i]) m.render(roots[i], modules[i].view(controllers[i])) @@ -642,7 +648,7 @@ Mithril = m = new function app(window) { var unwrap = (e.type == "load" ? xhrOptions.unwrapSuccess : xhrOptions.unwrapError) || identity var response = unwrap(deserialize(extract(e.target, xhrOptions))) if (e.type == "load") { - if (response instanceof Array && xhrOptions.type) { + if (type.call(response) == "[object Array]" && xhrOptions.type) { for (var i = 0; i < response.length; i++) response[i] = new xhrOptions.type(response[i]) } else if (xhrOptions.type) response = new xhrOptions.type(response)