Skip to content

Add inputType for InputEvent #23

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

Merged
merged 4 commits into from
Sep 24, 2023
Merged

Conversation

MonaMayrhofer
Copy link
Contributor

@MonaMayrhofer MonaMayrhofer commented Sep 7, 2023

Description of the change

Closes #22

In detail this implements the inputType property of InputEvents. The list of values for the inputType is taken from here


Checklist:

  • Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)")
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation
  • Added a test for the contribution (if applicable)

@MonaMayrhofer
Copy link
Contributor Author

I would greatly appreciate feedback on code and style as I am not yet very familiar with the customs in purescript. 😄

Also I would love to get some guidance regarding tests / documentation, as I couldn't find any of those within this repository that I could use as a reference. 👀

Thanks a lot!

Copy link
Member

@garyb garyb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I just have a few nitpicky convention/style remarks!

@@ -23,3 +26,9 @@ toEvent = unsafeCoerce
foreign import data_ :: InputEvent -> String

foreign import isComposing :: InputEvent -> Boolean

foreign import inputType_ :: InputEvent -> String
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest putting the _ at the start rather than the end (that's the usual convention for private FFI functions), and give the module an export list explicit with this hidden from the exports.

The _ at the end for data is because data is a reserved syntactic term in PS. 😉

foreign import inputType_ :: InputEvent -> String

inputType :: InputEvent -> Maybe InputType
inputType = toEnumInputType <<< inputType_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having this as a Maybe I'd suggest including an Other String constructor in InputType that will collect anything that falls through.

| FormatFontColor
| FormatFontName

derive instance eqInputType :: Eq InputType
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deriving Ord would be good too.

instance showInputType :: Show InputType where
show = fromEnumInputType

toEnumInputType :: String -> Maybe InputType
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd usually call this function parse.

toEnumInputType _ = Nothing

fromEnumInputType :: InputType -> String
fromEnumInputType InsertText = "insertText"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I'd call this one print.

@@ -0,0 +1,155 @@
module Web.UIEvent.InputEvent.InputTypes where
Copy link
Member

@garyb garyb Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't tend to pluralise in module names, so I'd just call this Web.UIEvent.InputEvent.InputType.

edit: Caveat - unless the module is just a collection of values of another type that is defined elsewhere, like EventTypes modules. 😉

@MonaMayrhofer
Copy link
Contributor Author

Thanks a lot for all the insightful feedback :D
I believe all of that should now be fixed and ready for another look!

@MonaMayrhofer MonaMayrhofer marked this pull request as ready for review September 13, 2023 08:28
@garyb
Copy link
Member

garyb commented Sep 24, 2023

Thanks very much!

@garyb garyb merged commit 99a17cc into purescript-web:master Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

InputEvent inputType missing
2 participants