1

I'm just experimenting with Om, learning from the basic tutorial.

My program data is in a single atom : app-state.

If I put a sequence into that atom, eg.

(defonce app-state (atom {:things [1 2 3 4]}))

Then later on, in my rendering, I can get a cursor

(let [things (:things data)] ... )

and map across it :

(map #(* % %) things)

However, if I have a defrecord with a method that can return a sequence :

(defrecord ThingCollection [xs]
    IThingCollection
    (getSeq [this] ... ) )

and put THAT into the application state

(defonce app-state (atom {:things (->ThingCollection [1 2 3 4]})))

...

(let [things (:things data)] ... )

I can't do this :

(map #(* % %) (.getSeq things))

It just throws an error saying that a cursor has no method .getSeq

That makes sense. But then how can I actually get at the ThingCollection object inside the cursor? I can't find any examples of this. And nothing I've tried seems to give it to me.

interstar
  • 26,048
  • 36
  • 112
  • 180

1 Answers1

0

Try (getSeq things).

Few notes:

  1. Prefer kebab-case get-seq instead of getSeq
  2. ->ThingCollection doesn't give an object, it just gives a record. This is still immutable and roughly just a "named map".
  3. Once you realize point 2, using .method call should look wrong because that is for dealing with JavaScript objects.
bostonou
  • 1,194
  • 10
  • 21