From 1321aec9fb27f02d9b889fda1b0f5cfb298baee6 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Fri, 14 Nov 2014 22:54:16 -0500 Subject: [PATCH] inline flatten --- mithril.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/mithril.js b/mithril.js index 95e0312b..8a2d1166 100644 --- a/mithril.js +++ b/mithril.js @@ -108,7 +108,14 @@ Mithril = m = new function app(window, undefined) { } if (dataType == sArr) { - data = flatten(data); + //recursively flatten array + for (var i = 0; i < data.length; i++) { + if (type.call(data[i]) == sArr) { + data = data.concat.apply([], data); + i-- //check current index again and flatten until there are no more nested arrays at that index + } + } + var nodes = [], intact = cached.length === data.length, subArrayCount = 0; //keys algorithm: sort elements without recreating them if keys are present @@ -390,16 +397,6 @@ Mithril = m = new function app(window, undefined) { } return nodes } - function flatten(data) { - //recursive flatten - for (var i = 0; i < data.length; i++) { - if (type.call(data[i]) == sArr) { - data = data.concat.apply([], data); - i-- //check current index again and flatten until there are no more nested arrays at that index - } - } - return data - } function autoredraw(callback, object) { return function(e) { e = e || event;