Skip to content

Commit e319358

Browse files
committed
Add Event utilities
1 parent 539cddc commit e319358

File tree

10 files changed

+336
-146
lines changed

10 files changed

+336
-146
lines changed

Diff for: bower.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"dependencies": {
1010
"purescript-functions": "^3.0.0",
1111
"purescript-eff": "^3.1.0",
12-
"purescript-unsafe-coerce": "^3.0.0"
12+
"purescript-unsafe-coerce": "^3.0.0",
13+
"purescript-nullable": "^3.0.0"
1314
}
1415
}

Diff for: generated-docs/React/Basic.md

+6-41
Original file line numberDiff line numberDiff line change
@@ -63,33 +63,6 @@ Render an Array of children without a wrapping component.
6363
Provide a key when dynamically rendering multiple fragments along side
6464
each other.
6565

66-
67-
### Re-exported from React.Basic.Types:
68-
69-
#### `SyntheticEvent`
70-
71-
``` purescript
72-
type SyntheticEvent = { bubbles :: Boolean, cancelable :: Boolean, currentTarget :: DOMNode, defaultPrevented :: Boolean, eventPhase :: Number, isTrusted :: Boolean, target :: DOMNode, timeStamp :: Number, "type" :: String }
73-
```
74-
75-
Event data that we receive from React.
76-
77-
#### `ReactFX`
78-
79-
``` purescript
80-
data ReactFX :: Effect
81-
```
82-
83-
A placeholder effect for all React FFI.
84-
85-
#### `ReactComponent`
86-
87-
``` purescript
88-
data ReactComponent :: Type -> Type
89-
```
90-
91-
A React component which can be used from JavaScript.
92-
9366
#### `JSX`
9467

9568
``` purescript
@@ -98,28 +71,20 @@ data JSX :: Type
9871

9972
A virtual DOM element.
10073

101-
#### `EventHandler`
74+
#### `ReactComponent`
10275

10376
``` purescript
104-
type EventHandler = EffFn1 (react :: ReactFX) SyntheticEvent Unit
77+
data ReactComponent :: Type -> Type
10578
```
10679

107-
An event handler, which receives a `SyntheticEvent` and performs some
108-
effects in return.
80+
A React component which can be used from JavaScript.
10981

110-
#### `DOMNode`
82+
#### `ReactFX`
11183

11284
``` purescript
113-
data DOMNode :: Type
85+
data ReactFX :: Effect
11486
```
11587

116-
An _actual_ DOM node (not a virtual DOM element!)
117-
118-
#### `CSS`
119-
120-
``` purescript
121-
data CSS :: Type
122-
```
88+
A placeholder effect for all React FFI.
12389

124-
An abstract type representing records of CSS attributes.
12590

Diff for: generated-docs/React/Basic/DOM.md

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ text :: String -> JSX
1515

1616
Create a text node.
1717

18+
#### `CSS`
19+
20+
``` purescript
21+
data CSS :: Type
22+
```
23+
24+
An abstract type representing records of CSS attributes.
25+
1826
#### `css`
1927

2028
``` purescript

Diff for: generated-docs/React/Basic/DOM/Events.md

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
## Module React.Basic.DOM.Events
2+
3+
This module defines safe event function and property accessors.
4+
5+
#### `EventHandler`
6+
7+
``` purescript
8+
type EventHandler = EffFn1 (react :: ReactFX) SyntheticEvent Unit
9+
```
10+
11+
An event handler, which receives a `SyntheticEvent` and performs some
12+
effects in return.
13+
14+
#### `SyntheticEvent`
15+
16+
``` purescript
17+
data SyntheticEvent :: Type
18+
```
19+
20+
Event data that we receive from React.
21+
22+
#### `DOMNode`
23+
24+
``` purescript
25+
data DOMNode :: Type
26+
```
27+
28+
An _actual_ DOM node (not a virtual DOM element!)
29+
30+
#### `DOMEvent`
31+
32+
``` purescript
33+
data DOMEvent :: Type
34+
```
35+
36+
The underlying browser Event
37+
38+
#### `EventFn`
39+
40+
``` purescript
41+
newtype EventFn a b
42+
```
43+
44+
##### Instances
45+
``` purescript
46+
Semigroupoid EventFn
47+
Category EventFn
48+
```
49+
50+
#### `bubbles`
51+
52+
``` purescript
53+
bubbles :: EventFn SyntheticEvent Boolean
54+
```
55+
56+
#### `cancelable`
57+
58+
``` purescript
59+
cancelable :: EventFn SyntheticEvent Boolean
60+
```
61+
62+
#### `currentTarget`
63+
64+
``` purescript
65+
currentTarget :: EventFn SyntheticEvent DOMNode
66+
```
67+
68+
#### `defaultPrevented`
69+
70+
``` purescript
71+
defaultPrevented :: EventFn SyntheticEvent Boolean
72+
```
73+
74+
#### `eventPhase`
75+
76+
``` purescript
77+
eventPhase :: EventFn SyntheticEvent Int
78+
```
79+
80+
#### `eventPhaseNone`
81+
82+
``` purescript
83+
eventPhaseNone :: Int
84+
```
85+
86+
#### `eventPhaseCapturing`
87+
88+
``` purescript
89+
eventPhaseCapturing :: Int
90+
```
91+
92+
#### `eventPhaseAtTarget`
93+
94+
``` purescript
95+
eventPhaseAtTarget :: Int
96+
```
97+
98+
#### `eventPhaseBubbling`
99+
100+
``` purescript
101+
eventPhaseBubbling :: Int
102+
```
103+
104+
#### `isTrusted`
105+
106+
``` purescript
107+
isTrusted :: EventFn SyntheticEvent Boolean
108+
```
109+
110+
#### `nativeEvent`
111+
112+
``` purescript
113+
nativeEvent :: EventFn SyntheticEvent DOMEvent
114+
```
115+
116+
#### `preventDefault`
117+
118+
``` purescript
119+
preventDefault :: EventFn SyntheticEvent SyntheticEvent
120+
```
121+
122+
#### `isDefaultPrevented`
123+
124+
``` purescript
125+
isDefaultPrevented :: EventFn SyntheticEvent Boolean
126+
```
127+
128+
#### `stopPropagation`
129+
130+
``` purescript
131+
stopPropagation :: EventFn SyntheticEvent SyntheticEvent
132+
```
133+
134+
#### `isPropagationStopped`
135+
136+
``` purescript
137+
isPropagationStopped :: EventFn SyntheticEvent Boolean
138+
```
139+
140+
#### `target`
141+
142+
``` purescript
143+
target :: EventFn SyntheticEvent DOMNode
144+
```
145+
146+
#### `timeStamp`
147+
148+
``` purescript
149+
timeStamp :: EventFn SyntheticEvent Number
150+
```
151+
152+
#### `type_`
153+
154+
``` purescript
155+
type_ :: EventFn SyntheticEvent String
156+
```
157+
158+

Diff for: generated-docs/React/Basic/Types.md

-60
This file was deleted.

Diff for: src/React/Basic.purs

+12-3
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,25 @@ module React.Basic
55
, createElementKeyed
66
, fragment
77
, fragmentKeyed
8-
, module React.Basic.Types
8+
, JSX
9+
, ReactComponent
10+
, ReactFX
911
) where
1012

1113
import Prelude
1214

1315
import Control.Monad.Eff (Eff, kind Effect)
1416
import Control.Monad.Eff.Uncurried (EffFn3, mkEffFn3)
1517
import Data.Function.Uncurried (Fn2, Fn3, mkFn3, runFn2)
16-
import React.Basic.Types (CSS, EventHandler, JSX, ReactComponent, ReactFX)
17-
import React.Basic.Types as React.Basic.Types
18+
19+
-- | A virtual DOM element.
20+
foreign import data JSX :: Type
21+
22+
-- | A React component which can be used from JavaScript.
23+
foreign import data ReactComponent :: Type -> Type
24+
25+
-- | A placeholder effect for all React FFI.
26+
foreign import data ReactFX :: Effect
1827

1928
-- | Create a React component from a _specification_ of that component.
2029
-- |

Diff for: src/React/Basic/DOM.purs

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77

88
module React.Basic.DOM where
99

10-
import React.Basic (ReactComponent, createElement)
11-
import React.Basic.Types (CSS, JSX, EventHandler)
10+
import React.Basic (JSX, ReactComponent, createElement)
11+
import React.Basic.DOM.Events (EventHandler)
1212
import Unsafe.Coerce (unsafeCoerce)
1313

1414
-- | Create a text node.
1515
text :: String -> JSX
1616
text = unsafeCoerce
1717

18+
-- | An abstract type representing records of CSS attributes.
19+
foreign import data CSS :: Type
20+
1821
-- | Create a value of type `CSS` (which can be provided to the `style` property)
1922
-- | from a plain record of CSS attributes.
2023
-- |
@@ -2162,4 +2165,3 @@ wbr
21622165
=> Record attrs
21632166
-> JSX
21642167
wbr = createElement (unsafeCreateDOMComponent "wbr")
2165-

Diff for: src/React/Basic/DOM/Events.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use strict";
2+
3+
exports.unsafePreventDefault = function(e) {
4+
e.preventDefault();
5+
return e;
6+
};
7+
8+
exports.unsafeIsDefaultPrevented = function(e) {
9+
e.isDefaultPrevented();
10+
return e;
11+
};
12+
13+
exports.unsafeStopPropagation = function(e) {
14+
e.stopPropagation();
15+
return e;
16+
};
17+
18+
exports.unsafeIsPropagationStopped = function(e) {
19+
return e.isPropagationStopped();
20+
};

0 commit comments

Comments
 (0)