I don't think it has anything to do with the cursor at all and is how you use build-all. (get app-state nil) should return nil abd (:items nil) should also return nil, so your cursor should be nil throughout.
The reason one way works and the other doesn't is you're using build-all differently in both cases. The one that works: (apply dom/div nil (om/build-all item-view items)) The one that doesn't work: (dom/div nil (om/build-all item-view items)) Note one calls apply and the other doesn't. Your code is slightly different because the version without apply has other elements before and after the build-all but it boils down to the same thing. If you see an OID rendered this is likely the cause. The simplest fix is to wrap the build-all in (apply dom/div nil ...) This is actually a common mistake in Om (until you internalise it), but my suggestion is to look into om-tools which largely fixes these gotchas (although, again, as you're passing a seq in the middle of the argument list you may still have to wrap it in a (dom/div ...) though you can ommit the apply and nil with om-tools. But I haven't tested it so it might not need this) On 17 Sep 2014 03:23, "Matthew Davidson" <[email protected]> wrote: > Erm, too much text? I'm just wondering if anyone knew how a component > using a cursor created with nil could still render properly (sometimes). > > Matthew > > On Friday, September 12, 2014 6:40:11 PM UTC-4, Matthew Davidson wrote: > > Hi, everyone! > > > > I have an Om problem, and I've looked all over the list archives and the > documentation, but haven't been able to find an explanation. I *think* it's > related to how cursors masquerade as/are constructed from vectors/maps, but > perusing om/core didn't reveal anything immediately. > > > > I've created a minimal test case to illustrate the problem. Basically, I > have an indexed cursor being created from app-state with nil as the index > "(get app-state nil)", which is then passed down. I would typically expect > some sort of failure to render, but my particular code path happened to > render ok, and I only found out the cursor was invalid after much-delayed > weirdness with channels and transact!. > > > > In one code path, it fails with an object identifier of some sort, but > in another, it renders perfectly. If the items-view function calls > build-all with item-view itself, rendering fails, but if items-view calls > item-list-view, which then calls build-all with item-view, it succeeds! > > > > The whole repo is at https://github.com/KingMob/om-cursor-test, but > below is the relevant code. This was tested with Om 0.7.1 and cljs 2322. > > > > Any help greatly appreciated, > > Matthew > > > > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > > ; Vector of item-groups > > (def app-state > > (atom [{ > > :items [ > > {:text "Alice"} > > {:text "Bob"} > > {:text "Cindy"} > > {:text "Dave"} > > ]} > > { > > :items [ > > {:text "Eve"} > > {:text "Fred"} > > {:text "Gina"} > > {:text "Howard"} > > ]}])) > > > > ; Just makes a button with text > > (defn item-view [item owner] > > (reify > > om/IRender > > (render [_] > > (dom/button nil > > (:text item))))) > > > > > > ; Somehow, by going through this function, it displays correctly > > (defn item-list-view [items owner] > > (reify > > om/IRender > > (render [_] > > (apply dom/div nil > > (om/build-all item-view items))))) > > > > > > (defn items-view [item-group owner] > > (reify > > om/IRender > > (render [_] > > (dom/div nil > > > > (dom/h3 nil "This one doesn't render a cursor > involving nil. Instead we get some sort of OID.") > > (om/build-all item-view (:items item-group)) ; > seems like it should be identical to call in item-list-view > > > > (dom/h3 nil "Yet this one renders with what seems > like an identical code path!") > > (om/build item-list-view (:items item-group)))))) > > > > > > (defn root-view [app-state owner] > > (reify > > om/IRender > > (render [_] > > (dom/div nil > > (om/build items-view (get app-state nil)) ; here, > we index into the vector of item-groups incorrectly, yet sometimes it > renders > > )))) > > -- > 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.
