From 83f84e5b6af035338a3b2416224055e65f6ec21d Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 20 Jan 2021 10:52:52 +0100 Subject: [PATCH] :bug: Fixes transient implementation --- common/app/common/pages/helpers.cljc | 32 +++++++++++++++++----------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/common/app/common/pages/helpers.cljc b/common/app/common/pages/helpers.cljc index b0e64e6c1..b96ac8af3 100644 --- a/common/app/common/pages/helpers.cljc +++ b/common/app/common/pages/helpers.cljc @@ -97,20 +97,26 @@ pending (transient []) next id] (let [children (get-in objects [next :shapes] []) - length (count children)] - (loop [i 0] - (when (< i length) - (let [child (nth children i)] - (conj! result child) - (conj! pending child) - (recur (inc i)))))) + [result pending] + ;; Iterate through children and add them to the result + ;; also add them in pending to check for their children + (loop [result result + pending pending + current (first children) + children (rest children)] + (if current + (recur (conj! result current) + (conj! pending current) + (first children) + (rest children)) + [result pending]))] - (let [length (count pending)] - (if (not= length 0) - (let [next (get pending (dec length))] - (pop! pending) - (recur result pending next)) - (persistent! result))))) + ;; If we have still pending, advance the iterator + (let [length (count pending)] + (if (pos? length) + (let [next (get pending (dec length))] + (recur result (pop! pending) next)) + (persistent! result)))))) (defn get-children-objects "Retrieve all children objects recursively for a given object"