Created
March 7, 2016 18:47
-
-
Save mhuebert/0b96b94037acec3e7880 to your computer and use it in GitHub Desktop.
Flat-Map, for multi-path atomic updates in Firebase
This file contains hidden or 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
(defn flat-map | |
([m] (clj->js (apply hash-map (flat-map "" m)))) | |
([path m] | |
(mapcat (fn [[k v]] (if (map? v) | |
((partial flat-map (str path "/" (name k))) v) | |
[(str path "/" (name k)) v])) m))) | |
(= (flat-map {:users {"x0x0x0" {:name "Matt" | |
:email "[email protected]"}}}) | |
{"users/x0x0x0/name" "Matt" | |
"users/x0x0x0/email" "[email protected]"}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment