From c00a8402fc7e0622278f59cc992eec2db5ef5578 Mon Sep 17 00:00:00 2001 From: Adam Dobrawy Date: Sun, 22 Dec 2019 02:41:05 +0100 Subject: [PATCH] Add support for function as branch node in tree --- src/omelette.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/omelette.js b/src/omelette.js index f745d8d..a2b59db 100644 --- a/src/omelette.js +++ b/src/omelette.js @@ -115,12 +115,9 @@ if (!(/\s+/.test(line.slice(-1)))) { lastIndex = -1; } - accessor = t => line.split(/\s+/).slice(1, lastIndex).filter(Boolean).reduce((a, v) => a[v], t); + accessor = t => line.split(/\s+/).slice(1, lastIndex).filter(Boolean).reduce((a, v) => a[v] instanceof Function ? a[v]() : a[v], t); replies = fragment === 1 ? Object.keys(objectTree) : accessor(objectTree); return reply((function(replies) { - if (replies instanceof Function) { - return replies(); - } if (replies instanceof Array) { return replies; }