Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposing more event data #167

Open
jerbaroo opened this issue Feb 27, 2017 · 0 comments
Open

Exposing more event data #167

jerbaroo opened this issue Feb 27, 2017 · 0 comments

Comments

@jerbaroo
Copy link
Contributor

jerbaroo commented Feb 27, 2017

Exposing more of the event data allows the user more freedom.

Take for example the mouse events,mousemove, mousedown etc. Currently the coordinates of the event relative to the source element are passed to the user: e.pageX - offset.left and e.pageY - offset.top. By exposing e.pageX and offset.left as separate items the user has more information to work with, the previous information can still be constructed.

The code in lib.js would be simplified such that each event returns the same data to Haskell, some values might be null or undefined.

In Haskell we would then convert from JSON to an event information data type:

data EventInfo = EventInfo {
    ePageX      :: Maybe Int
  , ePageY      :: Maybe Int
  , eOffsetLeft :: Maybe Int
  , eOffsetTop  :: Maybe Int
  , eWhich      :: Maybe Int
  , eValue      :: Maybe String
}

An existing event function's API would not change:

mousemove :: Element -> Event (Int,Int)
mousemove = fmap readCoordinates . domEvent "mousemove"

readCoordinates :: EventData -> (Int, Int)
readCoordinates json =
    (fromJust (ePageX e) - fromJust (eOffsetLeft e), fromJust (ePageY e) - fromJust (eOffsetTop e))
    where e = unsafeFromJSON json

However an additional function could expose more event information:

mousemove_ :: Element -> Event EventInfo
mousemove_ = fmap unsafeFromJSON . domevent "mousemove"

If there is support for this, I would be happy to work on it based on feedback 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants