Skip to content

Instantly share code, notes, and snippets.

@stevebuik
Created October 11, 2016 08:41
Show Gist options
  • Select an option

  • Save stevebuik/665511e028295f422ce21f2596b77c3a to your computer and use it in GitHub Desktop.

Select an option

Save stevebuik/665511e028295f422ce21f2596b77c3a to your computer and use it in GitHub Desktop.
recursive denormalization bug?
(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))
@stevebuik
Copy link
Author

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

@stevebuik
Copy link
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