Fork me on GitHub
#membrane
<
2022-03-14
>
Richie21:03:44

(defn view
  []
  (ui/on
   :mouse-down (fn [e] (do (println "mouse down") [[::hello-world]]))
   ::hello-world (fn [] (do (println "hello world") [[::what]]))
   (ui/button "hi")))

(ui/mouse-down (view) [0 0])
;; prints "mouse down" and returns `[[::hello-world]]`

(defn view
  []
  (ui/on-bubble
    (fn [events]
      (map #(case (first %)
              ::hello-world (do (println "hello world") [[::what]])
              %)
           events))
   (ui/on
    :mouse-down (fn [e] (do (println "mouse down") [[::hello-world]]))
    (ui/button "hi"))))

(ui/mouse-down (view) [0 0])
;; prints "hello world\nmouse down" and returns `([[:skipper.edit/what]])
` Why doesn't the first example work with ui/on? I expect it to behave the same as the second example with ui/on-bubble. Thanks!

👀 1
phronmophobic21:03:55

The order is the same as wrapping, ie. it works if ::hello-world is before :mouse-down

(defn view
  []
  (ui/on
   ::hello-world (fn [] (do (println "hello world") [[::what]]))
   :mouse-down (fn [e] (do (println "mouse down") [[::hello-world]]))
   
   (ui/button "hi")))

(ui/mouse-down (view) [0 0])
;; ([::what])

Richie21:03:25

That seems tricky. I don't know what I want to see though. I hope I'll form opinions as I go.