See response inline: On 25 July 2014 19:42, <[email protected]> wrote:
> hi! > > I've been following clojurescript/om for a while. I'm using clojure for a > product and read everything I can find on clojurescript and om. > > yesterday I finally decided to start working on something with om, after > some setup problems I finally got to display an svg circle on the screen... > > well almost :P > > https://twitter.com/EventFabricApp/status/492734199150182400 > > after getting ahead of the issue (I wanted to be sure that svg would be > feasible on all browsers before continuing) I'm planing on building a > simple svg app, I'm thinking on bouncing balls or a pong game, I will try > to write my experience as I work on it, but first I have some questions: > > * how do I handle recalculations periodically on components? a kind of > tick, something with setTimeout? > You can use setTimeout or core.async's timeout. Another method that I've used for animation is to increment the tick in om/IDidUpdate (storing it in local state), which then triggers a re-render (which in turn calls did-update and the loop continues). This code does a lot more than you need, but might help anyway: https://github.com/ddellacosta/om-transition/blob/master/src/om_transition/core.cljs and https://github.com/danielytics/ominate/blob/animated-components/src/ominate/core.cljs > > * how do I share some 'global' state with all components, like screen > size, mouse position, current pressed keys etc.? > Do all components really need to know about these things? If they do, then you can either store them "somewhere" outside of the Om components (eg an atom in a def) like Gary suggested, or you could store them in Om shared state: https://github.com/swannodette/om/wiki/Documentation#get-shared > > I've seen that core.async is used a lot for this kind of things, but I get > the idea (surely wrong) that for each component that wants to be notified > of changes in those things will have to create a copy of the channel? > It depends on what you are trying to do. If you just want a parent component to send data to a child component, passing state through om/build is usually sufficient (and IMHO preferred): (om/build my-component data {:state {:some-value x}}) Otherwise you can use mult/tap or pub/sub. mult and tap are for when you have many readers that should all receive the same value. It also keeps all readers in sync (next value won't be taken until all readers take previous value). pub and sub are kind of like a mixture between multimethods and mult/tap: you give pub a dispatch function that returns a topic, similar to a multimethod and then each subscriber specifies a topic. Each subscriber with the same topic is passed the value in the same way as mult/tap does. If you just want all components to get notified, use mult/tap. If you want to have components be able to specify which notifications to receive, use pub/sub. > > if you can enlighten me on this issues or point me to examples that use > mouse/keyboard/setInterval I will be really happy. > > thanks in advance! > > -- > 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.
