Allow user to choose how mouse position is computed in mouse events#62
Allow user to choose how mouse position is computed in mouse events#62themoritz wants to merge 4 commits intoreflex-frp:developfrom
Conversation
|
I completely agree with the problem you've described here, but I worry about needing to make additional breaking changes in the future to support new use cases. For example, what about modifier keys? I'm not sure it's sustainable to try to foresee what the user might need. Do you have any thoughts on how we can extend this to a more general interface? |
|
I totally see your point. I guess if we want to solve the problem once and for all then all mouse related events should return an e <- domEvent Mousemove el
let xyOffset = (mouseEventOffsetX &&& mouseEventOffsetY) <$> e(Similarly, Ideally, we wouldn't need to recreate the MouseEvent datatype, but instead leverage on the functions that are already in ghcjs-dom by making them available to the user. Let's say we have a monadic fmap for events, then I could for example write e <- domEvent Mousemove el -- e :: ev, IsMouseEvent ev
xOffset <- fmapM (liftIO . getOffsetX) eBut this is probably less user friendly than the first version |
|
Yep, I think that might be the way to go eventually! We can't do IO directly when mapping over Events, since that would make Reflex non-deterministic, but the user can use performEvent as necessary. I think an approach like the purescript-halogen one might be best. |
50dc715 to
aa86b10
Compare
|
The diff now shows how the halogen approach might look like. Next step would be to populate the records for the different event result types. Interestingly, for example |
|
Okay, I added the properties that I think make sense. Some remarks:
|
Usage would be:
Drawback is that it breaks usage of
Mousemove,MouseupandMousedown.An alternative would be to introduce event types like
MousemoveOffsetetc. But then it's not clear whyMousemoveshould yield(e.clientX, e.clientY)...