ckirkendall / kioo

Enlive/Enfocus style templating for Facebook's React and Om in ClojureScript.
Eclipse Public License 1.0
404 stars 39 forks source link

access to owner inside on-mount listener? #33

Closed ghost closed 9 years ago

ghost commented 9 years ago

is there any way to access the compoment's owner inside on-mount (and other react events) listener? I would like to call om/get-node and have no idea where should I get the owner from...

ckirkendall commented 9 years ago

I will have to experiment but you should be able to reference 'this'.

ckirkendall commented 9 years ago

hakslor, maybe I misunderstood your question. You can always access the owner in any defsnippet or deftemplate by making it an arg for the function.

(defsnippet tmp "...path..." [:#my-snippet] 
  [data owner opts]
  {[:my-snippet] (lifecycle 
                   {:on-mount (fn [this] 
                               (js/console.log (pr-str (om/get-props owner)))})})
ghost commented 9 years ago

this is also how I solved it on my side. I thought there is a bit more convenient way eg. owner exposed as an additional parameter in lifecycle functions like :on-mount (fn [this owner] ...).

anyway, thanks for answer :)