Fork me on GitHub
#om
<
2017-09-14
>
minhnh04:09:30

hi, I'm a newbie. I don't know what the Om component means in om/component?

(defui HelloWorld
  Object
  (render [this]
    (dom/div nil "Hello, world!")))

(def hello (om/factory HelloWorld))
I tried:
(om/component? HelloWorld)
(om/component? hello)
Both commands returned false

levitanong08:09:49

@minhnh om/component? actually checks for a component instance. For example,

(defui HelloWorld
  Object
  (render [this]
    (println (om/component? this))
    (dom/div nil "Hello, world!")))

;; true

minhnh08:09:57

How can I get this outside render function

levitanong08:09:49

If you’re using the repl, you can go (om/component? (om/class->any reconciler HelloWorld))

levitanong08:09:28

om/class->any asks the reconciler for some instance (if there are several instances, it’ll return one of them) of the HelloWorld class.

levitanong08:09:20

If you’re looking for a specific instance, (om/component? (om/ref->any reconciler [:something/by-id 0])), where [:something/by-id 0] is an ident

minhnh08:09:34

👍 This is what I need. Thank you

levitanong08:09:25

you’re welcome. ref->any can do more, but I’ll just leave this here for brevity. https://github.com/omcljs/om/wiki/Documentation-(om.next)#ref-any