-
Notifications
You must be signed in to change notification settings - Fork 10
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
Conversation
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! |
There was a problem hiding this 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!
src/Web/UIEvent/InputEvent.purs
Outdated
@@ -23,3 +26,9 @@ toEvent = unsafeCoerce | |||
foreign import data_ :: InputEvent -> String | |||
|
|||
foreign import isComposing :: InputEvent -> Boolean | |||
|
|||
foreign import inputType_ :: InputEvent -> String |
There was a problem hiding this comment.
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. 😉
src/Web/UIEvent/InputEvent.purs
Outdated
foreign import inputType_ :: InputEvent -> String | ||
|
||
inputType :: InputEvent -> Maybe InputType | ||
inputType = toEnumInputType <<< inputType_ |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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. 😉
Thanks a lot for all the insightful feedback :D |
Thanks very much! |
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: