Created
October 11, 2016 08:41
-
-
Save stevebuik/665511e028295f422ce21f2596b77c3a to your computer and use it in GitHub Desktop.
recursive denormalization bug?
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
| (require '[om.next :as om]) | |
| (require '[clojure.pprint :refer [pprint]]) | |
| (def initial-state | |
| {:root {:id 1 | |
| :name "root" | |
| :type :branch | |
| :children [{:id 2 | |
| :type :leaf | |
| :name "first child"} | |
| {:id 3 | |
| ; switch value below to :leaf for correct behaviour | |
| :type :branch | |
| :name "second child"}]}}) | |
| (om/defui RecursiveWidget | |
| static om/Ident | |
| (ident [this props] | |
| ((juxt :type :id) props)) | |
| static om/IQuery | |
| (query [this] | |
| '[:id :type {:children ...}])) | |
| (om/defui RootWidget | |
| static om/IQuery | |
| (query [this] | |
| `[{:root ~(om/get-query RecursiveWidget)}])) | |
| (pprint (om/tree->db RootWidget initial-state true)) |
Author
Author
tested in clj and cljs and the behaviour is the same for both.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the result of the pprint is
{:root [:branch 1],
:leaf
{2 {:id 2, :type :leaf, :name "first child"},
3 {:id 3, :type :branch, :name "second child"}},
:branch
{1
{:id 1,
:name "root",
:type :branch,
:children [[:leaf 2] [:branch 3]]}},
:om.next/tables #{:leaf :branch}}
you can see the record with id 3 is in the wrong part of the tree