-
Notifications
You must be signed in to change notification settings - Fork 40
Move shared Events stuff out of React.Basic.DOM #26
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5fc1f5b
Use Maybe in targetValue and targetChecked
maddie927 a6a710e
Move shared Events stuff out of React.Basic.DOM
maddie927 a148686
Add warning to docs
maddie927 c6ae2e2
Hide `EventFn` constructor and expose `unsafeEventFn`
maddie927 2f0b68e
Improve `unsafeEventFn` warning/explantion
maddie927 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
## Module React.Basic.Events | ||
|
||
#### `EventHandler` | ||
|
||
``` purescript | ||
type EventHandler = EffFn1 (react :: ReactFX) SyntheticEvent Unit | ||
``` | ||
|
||
An event handler, which receives a `SyntheticEvent` and performs some | ||
effects in return. | ||
|
||
#### `SyntheticEvent` | ||
|
||
``` purescript | ||
data SyntheticEvent :: Type | ||
``` | ||
|
||
Event data that we receive from React. | ||
|
||
#### `EventFn` | ||
|
||
``` purescript | ||
newtype EventFn a b | ||
``` | ||
|
||
Encapsulates a safe event operation. `EventFn`s can be composed | ||
to perform multiple operations. | ||
|
||
For example: | ||
|
||
```purs | ||
input { onChange: handler (preventDefault >>> targetValue) | ||
\value -> setState \_ -> { value } | ||
} | ||
``` | ||
|
||
##### Instances | ||
``` purescript | ||
Semigroupoid EventFn | ||
Category EventFn | ||
(IsSymbol l, RowCons l (EventFn a b) fns_rest fns, RowCons l b r_rest r, RowLacks l fns_rest, RowLacks l r_rest, Merge rest fns_rest a r_rest) => Merge (Cons l (EventFn a b) rest) fns a r | ||
``` | ||
|
||
#### `unsafeEventFn` | ||
|
||
``` purescript | ||
unsafeEventFn :: forall a b. (a -> b) -> EventFn a b | ||
``` | ||
|
||
Unsafely create an `EventFn`. This function should be avoided. | ||
Use the helper functions specific to your platform (such as `React.Basic.DOM.Events`). | ||
|
||
#### `handler` | ||
|
||
``` purescript | ||
handler :: forall a. EventFn SyntheticEvent a -> (a -> Eff (react :: ReactFX) Unit) -> EventHandler | ||
``` | ||
|
||
Create an `EventHandler`, given an `EventFn` and a callback. | ||
|
||
For example: | ||
|
||
```purs | ||
input { onChange: handler targetValue | ||
\value -> setState \_ -> { value } | ||
} | ||
``` | ||
|
||
#### `merge` | ||
|
||
``` purescript | ||
merge :: forall a fns fns_list r. RowToList fns fns_list => Merge fns_list fns a r => { | fns } -> EventFn a ({ | r }) | ||
``` | ||
|
||
Merge multiple `EventFn` operations and collect their results. | ||
|
||
For example: | ||
|
||
```purs | ||
input { onChange: handler (merge { targetValue, timeStamp }) | ||
\{ targetValue, timeStamp } -> setState \_ -> { ... } | ||
} | ||
``` | ||
|
||
#### `Merge` | ||
|
||
``` purescript | ||
class Merge (rl :: RowList) fns a r | rl -> fns, rl a -> r where | ||
mergeImpl :: RLProxy rl -> { | fns } -> EventFn a ({ | r }) | ||
``` | ||
|
||
##### Instances | ||
``` purescript | ||
Merge Nil () a () | ||
(IsSymbol l, RowCons l (EventFn a b) fns_rest fns, RowCons l b r_rest r, RowLacks l fns_rest, RowLacks l r_rest, Merge rest fns_rest a r_rest) => Merge (Cons l (EventFn a b) rest) fns a r | ||
``` | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Might be worth commenting briefly on why this function is dangerous (it lets SyntheticEvents leave the current scope). Otherwise, this PR looks good to me 👍