[ClojureScript] Wrapping all def into a load event handler

133 views
Skip to first unread message

Takahiro Hozumi

unread,
Dec 26, 2011, 10:58:00 AM12/26/11
to Clojure
Hi,
In order to manipulate dom, I often want to bind elements into
variable through def, but we cannot manipulate it until load event.
So I wrapped all def into a load event handler in the following way.
https://gist.github.com/1521051
I don't use let, because many elements cause deep nested let,
and I don't use atom to store elements, because reset! and deref are
not necessary by binding element directly.
Is this bad way in ClojureScript? Is there a downside?

Thanks.

Stuart Sierra

unread,
Jan 1, 2012, 12:38:55 PM1/1/12
to clo...@googlegroups.com
Hi Takahiro,

This will work. It's not 100% idiomatic Clojure, but it's an acceptable workaround to the DOM loading issue.

If ClojureScript had `alter-var-root`, which it doesn't, you could use that to set the Vars in your init function. But ClojureScript doesn't really have Vars either, so I wouldn't expect to see `alter-var-root`.

If ClojureScript had Clojure's `delay`, you could use that. ClojureScript doesn't have `delay`, but it might make sense to add it.

The easiest way, of course, is to load your JavaScript at the bottom of your HTML file, but that's not always convenient.

-Stuart Sierra
clojure.com

Takahiro

unread,
Jan 3, 2012, 3:39:19 AM1/3/12
to clo...@googlegroups.com
Hi,
Putting javascript at the bottom of body is nice idea.
Thanks.

2012/1/2 Stuart Sierra <the.stua...@gmail.com>:

> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

Reply all
Reply to author
Forward
0 new messages