Skip to content

Instantly share code, notes, and snippets.

@darkone23
Forked from dillonforrest/om-example.md
Last active January 4, 2016 08:19
Show Gist options
  • Save darkone23/8595096 to your computer and use it in GitHub Desktop.
Save darkone23/8595096 to your computer and use it in GitHub Desktop.

Confusion around om functionality

(defn static-data []
  (for [row (range 10)]
    {:a "some" :b "fake" :c "data"}))

(def app-state (atom {:items (static-data)}))

;;; components

(defn item [_ _]
  (om/component
    (dom/div nil "I'm a row of data")))

(defn list [state _]
  (om/component
    (apply dom/div nil
      (om/build-all item (:items state)))))
    
;;; mount!!

(om/root app-state list (.getElementById js/document.body))

I get this error in my Chrome console: Uncaught Error: Cannot build Om component from non-cursor {:a "some" :b "fake" :c "data"}.

Why can't om create a cursor into this? Wouldn't it just be something like [:items n] Any thoughts?

@darkone23
Copy link
Author

To anyone who finds this, the restriction is that 'for' comprehensions, or filters/maps/etc return LISTS.

Om only operates on associative data structures, a list is not one of those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment