Last active
April 26, 2016 16:01
-
-
Save yochannah/82c3700cf7b14ed5cc94f1f7ae80991f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns breadth.views | |
(:require [re-frame.core :as re-frame] | |
[json-html.core :as json-html]) | |
(:use [json-html.core :only [edn->hiccup]])) | |
(defn mymap [] | |
[{:self :a | |
:myval " x " | |
:children | |
[ | |
{:self :b | |
:myval " y " | |
:children | |
[{:self :d | |
:children [] | |
:myval " z "}]} | |
{:self :c | |
:children [] | |
:myval " Q "}] | |
}]) | |
(defn do-the-thing [val new-thing] | |
(.log js/console val new-thing) | |
(str val new-thing) | |
) | |
(defn do-one-level [level my-fab-string] | |
(map (fn [thingy] | |
;;do the calculation, whatever it is | |
(update-in thingy [:myval] do-the-thing my-fab-string) | |
) level)) | |
(defn iterate-mymap [the-map my-fab-string] | |
(let [calculated-vals (do-one-level the-map my-fab-string)] | |
(map-indexed (fn [index map-child] | |
(.group js/console "%cMap Item:" "border-bottom:solid 3px cornflowerblue" (clj->js (:self map-child)) "My fab string:" my-fab-string) | |
(cond (seq (:children map-child)) | |
;recursively calculate the children | |
(update-in map-child [:children] | |
(fn [] (iterate-mymap (:children map-child) (:myval map-child)))) | |
;return without any recursion if there are children | |
(empty? (:children map-child)) map-child)) | |
calculated-vals))) | |
(defn main-panel [] | |
(let [name (re-frame/subscribe [:name])] | |
(fn [] | |
[:div.db | |
[:h3 "Original map"] | |
(edn->hiccup (mymap)) | |
[:h3 "Iterated map"] | |
(edn->hiccup (iterate-mymap (mymap) "R ")) | |
]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment