On Sunday, November 16, 2014 10:08:10 PM UTC-5, David Mohl wrote:
> On Sunday, November 16, 2014 8:12:55 PM UTC+9, Daniel Kersten wrote:
> > You have the right idea. I believe the mistake in your code is that 
> > om/build is being called outside of render (or a function called by 
> > render). If you change your code to something like the following, it should 
> > work:
> > 
> > (defn default-view [app owner opts]
> >   (om/component (dom/h1 nil "Default View")))
> > 
> > (defn root-app [app] (om/component (om/build (:view app) app)))
> > (def app-state (atom {:view default-view}))
> > 
> > (om/root app-state root-app (aget (.getElementsByClassName js/document 
> > "main") 0)) 
> > 
> > 
> > 
> > On 16 November 2014 08:08, David Mohl <[email protected]> wrote:
> > Hey Guys,
> > 
> > 
> > 
> > I am very fresh to clojurescript and love it so far. I am in fact currently 
> > trying to build my first webapp using clojure and compojure for the 
> > backend, and om combined with secretary for the frontend, but I have a lot 
> > of issues.
> > 
> > 
> > 
> > While I slowly get a grasp of om, I am trying to 'switch' pages (or views?) 
> > to give that feel of a responsive single-page app. To implement this, I 
> > 'thought' I could simply create a root-app which mounts my other views when 
> > I need them. Something like this:
> > 
> > 
> > 
> > (defn default-view [app owner opts]
> > 
> >   (om/component (dom/h1 nil "Default View")))
> > 
> > 
> > 
> > (defn root-app [app] (om/component (:view app)))
> > 
> > (def app-state (atom {:view (om/build default-view root-app)}))
> > 
> > (om/root app-state root-app (aget (.getElementsByClassName js/document 
> > "main") 0))
> > 
> > 
> > 
> > Very simple. The root app gets mounted into the main div, and the root app 
> > mounts whatever is under :view inside the app-state. Works fine so far.
> > 
> > 
> > 
> > I am access detail/1/, om mounts my detailview, the detailview mounts all 
> > the components that it needs, one of them loading ajax. Now here comes my 
> > problem, I am trying to use om/transact to change state. Something like:
> > 
> > 
> > 
> > om/IInitState
> > 
> > (init-state [_] (om/transact! app [:data] (fn [] [])))
> > 
> > 
> > 
> > om/IWillMount
> > 
> > (will-mount [_]  (go (let [foo (<! (fetch-something))]
> > 
> >            (om/update! app #(assoc % :data foo)))))
> > 
> > 
> > 
> > (I learned that from a example. (fetch-something) is doing a simple ajax 
> > call through core.async.)
> > 
> > 
> > 
> > Now when executing I am getting: "No protocol method ITransact.-transact! 
> > defined for type function: function root_app(app){if(typeof 
> > picky.core.t16273 !== 'undefined'). "
> > 
> > 
> > 
> > This error tells me that ITransact is not implemented in my root_app which 
> > I used for building all the other components. So I must have done something 
> > wrong or the approach of using a root_app to mount everything else is 
> > simply not working.
> > 
> > 
> > 
> > Anyone here who can point me into the right direction? Would appreciate any 
> > help
> > 
> > 
> > 
> > --
> > 
> > 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.
> 
> This seems to work, thank you for the hint! 
> 
> Now the problem is that when I build the app inside the root-app, I can't 
> pass opts directly into the view. 
> Right now I am building the view directly in secretary with the url 
> parameters and push it into the app state where it then gets mounted by the 
> root app. 
> 
> How are you handling parameters with this approach?

This specific question really requires more context (a complete but minimal 
case would be best).  That said, it might help to step back and reinforce your 
understanding of the fundamentals a bit.  These more complex scenarios really 
fall into place more naturally once you have a firm grasp of the rationale 
behind Om's core functions.

If you haven't been through the Om tutorials, it's definitely worth stepping 
through them slowly and carefully. You may also find it helpful to take a look 
at this Om SPA example.  It uses silk for routing rather than secretary, but it 
demonstrates several of the concepts you're working through.

GitHub repo: https://github.com/cascada-io/om-spa
Demo: http://om-spa.azurewebsites.net/

-- 
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.

Reply via email to