Instead of having the multimethods return components, you could have them
return functions which return components. That way you pass different functions
to build for different types. Like this:
(defmulti get-entry-view (fn [person] (:type person)))
(defmethod get-entry-view :student
[person] student-view)
(defmethod get-entry-view :professor
[person] professor-view)
And then use it like this:
(om/build (get-entry-view (om/value person)) person)
On Monday, July 21, 2014 12:33:42 AM UTC-7, feng zhou wrote:
> On Friday, July 18, 2014 2:02:54 AM UTC+10, Jarppe Länsiö 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..
>
>
>
> Using conditionals seems to be the easiest way to avoid state problems in
> multimethod.
>
>
>
> My guess is, multimethod should be avoided if a component has local state.
> Om's tutorial only used multimethods for components that do not have local
> state, just that it doesn't discuss potential issues and limitations of
> multimethod.
>
>
>
> With the limitation on mount/unmount that Daniel pointed out, I think it's
> easiest to not use multimethods.
--
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.