I show the menu in Om using the component and subcomponent, for example:
(def app-state (atom {:location ""
:menuitems [["Pages" "/pages/"]
["Images" "/images/"]]}))
(defn menu-item-view [parent-cursor item owner]
(reify
om/IRender
(render [this]
(dom/li
(dom/a
{:onClick (fn [_] (swap! app-state assoc :location (last @item)))}
(first item))))))
(defn menu-view [app owner]
(reify
om/IRender
(render [this]
(dom/li
(dom/a nil "Menu")
(apply dom/ul
(om/build-all (partial menu-item-view app)
(:menuitems app)))))))
(om/root menu-view app-state
{:target (. js/document (getElementById "menu"))})
My question is: how to update (@ app-state: location) and reinstall the menu correctly?
Update in the code above:
(swap! app-state assoc :location (last @item))
It works, but the tree does not update correctly.
I suspect that I need to use om / update! or om / transact! but they take the cursor and the only cursor that I have in the menu item is the current menu item, not the full state of the application. Therefore, I cannot access: location.
How is this handled?
I would prefer to use avio core.async and channels if possible.
source
share