wrapper component causing re-rendering of all components rendered from a list

49 views
Skip to first unread message

Paul Cowan

unread,
Nov 8, 2014, 6:30:30 AM11/8/14
to clojur...@googlegroups.com
I am playing about with creating a wrapper component that I can add some simple animations to. I know there is ominate but this is just for my own tinkering.

I am rendering a number of dynamic components from a list like this:

(map #(om/build clip-view % {:key :id}) clips)

When I render the list like this, it only ever renders the newest item but when I add the wrapper component like this:

(map #(om/build (animate clip-view) % {:key :id}) clips)

The entire list gets re-rendered each time.

At the moment, there is no functionality in my wrapper component which looks like this:

(defn animate [component & args]
(fn [props owner opts]
(reify
om/IRender
(render [_]
(om/build component props {:opts opts})))))

Why would adding the wrapper cause all items to be re-rendered?

Colin Yates

unread,
Nov 8, 2014, 8:33:48 AM11/8/14
to clojur...@googlegroups.com
Might be a red-herring, but here goes:

Is it because animate is returning an anonymous function which is a no-no (as anonymous functions instances are not equal)?

What happens if you remove the (fn [..]) from animate so animate is (defn animate [...] (reify ...))?

Paul Cowan

unread,
Nov 8, 2014, 9:52:36 AM11/8/14
to clojur...@googlegroups.com
But then it is no longer a func that can be passed to om/build.

The func will just get executed unless I misunderstood you?

Cheers

Paul Cowan

Cutting-Edge Solutions (Scotland)



--
Note that posts from new members are moderated - please be patient with your first post.
---
You received this message because you are subscribed to a topic in the Google Groups "ClojureScript" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojurescript/RUCEFqzwdqQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojurescrip...@googlegroups.com.
To post to this group, send email to clojur...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.

Message has been deleted

Colin Yates

unread,
Nov 8, 2014, 11:16:57 AM11/8/14
to clojur...@googlegroups.com
Ignore my last post - I was being a numpty (serves me right for trying to work whilst looking after 4 kids!). Yes, you are right, om wants you to pass the var itself.

This is all about composing components in om, which I have run into myself and don't have a particularly elegant answer. I did think about passing the delegate to the wrapper via opts, or pass a builder into the decorator's opts, but I have no idea what will happen with om's state-tracking. Maybe it will work, no idea. Alternatively you could use multi-methods here - pass in the delegate's state to animate and have animate pass that state on (if needs be) to a multi-method? Similar to how professor-view and student-view are handled in the tutorial.

Sorry, I am just not familiar enough with om to help here, and I will be very interested to know the answer.

Paul Cowan

unread,
Nov 8, 2014, 12:15:17 PM11/8/14
to clojur...@googlegroups.com
Another thing I am noticing is that this.props.children is null.

this.props.children should give access to the child components http://facebook.github.io/react/docs/multiple-components.html.

Does om work differently or is there a reason why this is null?
Reply all
Reply to author
Forward
0 new messages