Not sure if this is relevant but it shows the use of did-mount and did-update to synchronise state with a js based UI element (Google maps).
http://infinitemonkeys.influitive.com/little-framework-big-splash/ On 14 Jan 2015 01:49, "Colin Yates" <[email protected]> wrote: > Hi Axel, > > First, as somebody else pointed out, om is a little bit young to have > definitive "right and wrong" answers, so it is even more important to > understand the context of those answers. > > So, in the context of relative newbie myself :), I am not entirely clear > what the problem is. Can you clarify please. > > Are you saying that app-state has {:model-objects [...]} and when added to > leaflet, leaflet generates a corresponding leafletModelObject? If so, is > your question "how do I update the corresponding leafletModelObject when > its "linked" om model-object changes? > > If so, this is where it gets a bit edgy. I find om is great when the whole > UI is a projection of app-state. No need to track the lifecycle of how > app-state evolved, it is just a pure function of the current om state. Here > you want to break that paradigm and start tracking how data has evolved. I > think that is fine and valid, but is a little bit more complicated. > > Assuming I am on the right track the ideal answer is recreate the > leafletModelObject every time the om model changes, moving back to the "UI > is only a projection of state" pattern. To do this I would suggest the > (render) function of the leaflet container is a good place as that is only > called when the input to render changes. > > If that isn't possible or too expensive then you can will need to manually > sync them, again, (render) seems a good place. You would end up with pseudo > code like: > > (render [{:keys [model-objects] :as cursor} owner] > (let [leaflet ... > leaflet-models (get-the-models-from leaflet) > updated-leaflet-models (sync model-objects leaflet-models)] > (update-leaflet-models leaflet updated-leaflet-models) > (om/build leaflet-etc))) > > "sync" could either check timestamps, recreate the leaflet-model and check > for differences etc, check a version, model-object could cache the > leaflet-model and do an equality check etc. > > However, as I say, I am making many assumptions about your usecase. To > repeat, the world becomes a much simpler place if your render function > doesn't care about time, it doesn't distinguish between creation and > editing, it simply gets the app-state and renders it (i.e. it recreates the > leaflet object every time). If like me your initial reaction was "wow, that > is going to be really slow", turns it JavaScript is much quicker than we > realise (except IE<9!). Give it a go and prove it is too slow. > > Hope that ramble helps :). > > > > > > On Monday, 12 January 2015 09:20:30 UTC, Axel Katerbau wrote: > > Hi! > > > > I'm relative new to Clojurescript and om and have a question regarding > the use of libraries that "produce" state in the context of an om app. > > > > The app uses the nice leaflet library to display a map. So far so good, > but it should also display markers for corresponding model objects > (properly residing in an app-state atom). Adding markers creates marker > objects that better be stored somewhere so they can be updated when the > model changes. > > > > My (newbie) question is: What is the best (tm) idea for updating and > storing these marker objects? > > > > - Axel > > -- > 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.
