I am currently trying to learn om.next.
This is the code that I have:
(ns hlearn.core
(:require [goog.dom :as gdom]
[om.next :as om :refer-macros [defui]]
[om.dom :as dom]
[sablono.core :as html :refer-macros [html]]))
(enable-console-print!)
(def app-data
(atom {:user ""
:main-menu {:selected :home}}))
;; -------------------------------------------------------------------------
;; Parsing
(defmulti read om/dispatch)
(defmethod read :selected
[{:keys [state]} _ _]
{:value (get-in @state [:main-menu :selected])})
;; -------------------------------------------------------------------------
;; Components
(defui MainMenu
static om/IQuery
(query [this]
[:selected])
Object
(render [this]
(let [{:keys [selected]} (om/props this)]
(println (= selected :home)))))
(def main-menu (om/factory MainMenu))
(defui RootView
Object
(render [this]
(println "Render RootView")
(main-menu)))
(def reconciler
(om/reconciler
{:state app-data
:parser (om/parser {:read read})}))
(om/add-root! reconciler
RootView (gdom/getElement "app"))
My goal here is that the component MainMenu
has to write true
on the console (currently writes false
).
Since the read function should return {:value :home}
(value on the app-state), therefore (= selected :home)
should be true.
In practice, MainMenu
writes false
on the console, because selected
has the value nil
.