I am looking for a nice way of only responding to mouseover events but only when the mouse is down. I'm looking for a more core.async way of doing this.
I have two channels in an om component:
om/IDidMount
(did-mount [_]
(let [canvas (q ".tutorial")
_ref (js/Firebase. "https://conseal.firebaseio.com/scribble")
ctx (.getContext canvas "2d")
mouse-down (om/get-state owner :mouse-down)
mouse-chan (om/get-state owner :mouse-chan)]
(listen canvas EventType.MOUSEDOWN #(put! mouse-down [:down %]))
(listen canvas EventType.MOUSEMOVE #(put! mouse-chan [:move %]))
I then have the following go-loop in IWillMount:
om/IWillMount
(will-mount [_]
(let [mouse-down (om/get-state owner :mouse-down)
mouse-chan (om/get-state owner :mouse-chan) ]
(go-loop []
(<! mouse-down)
(let [[evt-type e] (<! mouse-chan)]
(.log js/console (str evt-type " we are over " e)))
(recur))))
The above does not work because mousedown events are not continually sent. I'm looking for a core.async idiomatic way of handling this.
If I was using rxjs I could do something like this:
var mouseDrags = mouseDowns.select(function (downEvent) {
return mouseMoves.takeUntil(mouseUps).select(function (drag) {
return functionToGetStuffWeWant(drag);
});
});