From 5314888d46b3b3d3d65135d5c7fe8d9f9422cdb0 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Sun, 25 Jan 2015 22:14:14 -0500 Subject: [PATCH] extend --- mithril.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mithril.js b/mithril.js index 52cd4d78..bd56e1d3 100644 --- a/mithril.js +++ b/mithril.js @@ -235,14 +235,15 @@ var m = (function app(window, undefined) { if (module) { if (!controller) { var constructor = module.controller || m.prop() + for (var prop in constructor.prototype) data[prop] = constructor.prototype[prop] controller = constructor.call(data, data) || data + if (!controller.attrs) controller.attrs = {} } - else { - controller.tag = data.tag - for (var attr in data.attrs) controller.attrs[attr] = data.attrs[attr] - controller.children = data.children - } + controller.tag = data.tag + for (var attr in data.attrs) controller.attrs[attr] = data.attrs[attr] + controller.children = data.children data = module.view(controller) + if (!data.tag) throw new Error(module.view.toString() + "\n\nThis template must return a virtual element, not an array, string, etc."); } if (!data.attrs) data.attrs = {}; if (!cached.attrs) cached.attrs = {};