From 643e85cd5b36af5884834527352ba37ce36aae0c Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Thu, 26 Feb 2015 22:28:28 -0500 Subject: [PATCH] prevent early redraw if controller goes async --- mithril.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/mithril.js b/mithril.js index fd9e7b08..d2b21671 100644 --- a/mithril.js +++ b/mithril.js @@ -233,10 +233,10 @@ var m = (function app(window, undefined) { } else if (data != null && dataType === OBJECT) { if (data.view) { - var module = data + var module = data, onunload var controller = cached.controller || new (module.controller || function() {}) + data = pendingRequests == 0 ? module.view(controller) : {tag: "placeholder"} if (controller.onunload) unloaders.push({controller: controller, handler: controller.onunload}) - data = module.view(controller) if (!data.tag) throw new Error("Component template must return a virtual element, not an array, string, etc.") } if (!data.attrs) data.attrs = {}; @@ -269,7 +269,15 @@ var m = (function app(window, undefined) { data.children, nodes: [node] }; - if (controller) cached.controller = controller + if (controller) { + cached.controller = controller + if (controller.onunload.$old) controller.onunload = controller.onunload.$old + if (pendingRequests && controller.onunload) { + var onunload = controller.onunload + controller.onunload = function() {} + controller.onunload.$old = onunload + } + } if (cached.children && !cached.children.nodes) cached.children.nodes = []; //edge case: setting value on