Most likely you are hitting this limitation:
https://github.com/swannodette/om/issues/178
Om uses the function to decide if it needs to unmount/mount components.
Since the multimethod is always the same function (regardless of where it
then dispatches to), Om does not know that the component has changed.
I've encountered another case where the same thing happens but without
multimethods:
(reify
om/IRenderState
(render-state [_ {:keys [n]}]
(om/build (get [comp-a comp-b comp-b] n) {:state (get-state-for n)}))
I did this with a tab widget component where the child components are the
components to display depending on what tab is selected and is passed in as
opts. The problem here is because comp-b is used twice, switching between
tab 2 and tab 3 won't unmount/remount and (probably more importantly for
this use case), because it doesn't change the component, the local state
won't get swapped. If (get-state-for 1) returns {:foo "hi"} and then
(get-state-for 2) returns {}, because :state merges the maps, you will
still have {:foo "hi"} (and whatever else happens to have been set
internally already). Not sure there's a workaround other than being very
careful how you use components like this...
On 17 July 2014 17:02, Jarppe Länsiö <[email protected]> wrote:
> I have this same problem. I thought multimethods would be great way to
> render different views in simple page app, so I wrote something like this:
>
> (def app-state {:view :login})
>
> (defmulti render-view (fn [app owner] (:view app)))
>
> (defmethod render-view :login [app owner]
> (om/component
> ...
>
> (defmethod render-view :foo [app owner]
> (om/component
> ...
>
> (om/root
> render-view
> app-state
> {:target (js/document.getElementById "app")})
>
> This works, except that the local state does not work. I guess this is
> same problem Feng describes?
>
> What would be a work around? Shoud I just have a something like this:
>
> (om/root
> (fn [app owner]
> (condp = (:view app)
> :login (login-view app)
> ...one line for each view..
>
> --
> Note that posts from new members are moderated - please be patient with
> your first post.
> ---
> You received this message because you are subscribed to the Google Groups
> "ClojureScript" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/clojurescript.
>
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.