Fork me on GitHub
#hoplon
<
2018-01-13
>
thedavidmeister04:01:04

@flyboarder well to get a useful "dragleave" event using the dnd api you need to count dragenter/dragleave events because they trigger on some nested elements too

thedavidmeister04:01:33

so i end up with something like

thedavidmeister04:01:36

:dragenter (fn [e]
               (wheel.dom.events/prevent-default e)
               (swap! drag-enters update (-> e .-originalEvent .-target) inc))
   :dragleave (fn [e]
               (wheel.dom.events/prevent-default e)
               ; use a RAF to ensure leave is always called after enter but
               ; avoid the UI jank that a regular timeout would incur
               (.requestAnimationFrame js/window
                #(swap! drag-enters update (-> e .-originalEvent .-target) dec)))

thedavidmeister04:01:22

which really seems like something i should bundle up for re-use

thedavidmeister04:01:41

so i was assuming that i'd need to namespace the :dragenter and :dragleave attributes and put them in a fn that applies them to a passed element - namespacing would be to ensure that the element can have other things bound to the same events

thedavidmeister04:01:08

although, i haven't tested it yet, it might already work as event handling and attributes are different things

flyboarder18:01:10

@thedavidmeister so for that I would just namespace it