Skip to content

Commit ca42942

Browse files
committed
Merge pull request #36 from ethul/topic/spec-display-name
Topic/spec display name
2 parents 26df915 + ac1814e commit ca42942

File tree

6 files changed

+45
-38
lines changed

6 files changed

+45
-38
lines changed

Diff for: docs/React.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ A rendering function.
155155
#### `UISpec`
156156

157157
``` purescript
158-
type UISpec props state eff = { render :: Render props state eff, getInitialState :: UIRef -> Eff (props :: ReactProps props, state :: ReactState Disallowed state, refs :: ReactRefs Disallowed | eff) state, componentWillMount :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs Disallowed | eff) Unit, componentDidMount :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit, componentWillReceiveProps :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit, shouldComponentUpdate :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Boolean, componentWillUpdate :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit, componentDidUpdate :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadOnly state, refs :: ReactRefs ReadOnly | eff) Unit, componentWillUnmount :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadOnly state, refs :: ReactRefs ReadOnly | eff) Unit }
158+
type UISpec props state eff = { render :: Render props state eff, displayName :: String, getInitialState :: UIRef -> Eff (props :: ReactProps props, state :: ReactState Disallowed state, refs :: ReactRefs Disallowed | eff) state, componentWillMount :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs Disallowed | eff) Unit, componentDidMount :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit, componentWillReceiveProps :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit, shouldComponentUpdate :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Boolean, componentWillUpdate :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit, componentDidUpdate :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadOnly state, refs :: ReactRefs ReadOnly | eff) Unit, componentWillUnmount :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadOnly state, refs :: ReactRefs ReadOnly | eff) Unit }
159159
```
160160

161161
A specification of a component.

Diff for: src/React.js

+5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@ exports.mkUI = function(ss) {
3838
var result = {};
3939
for (var s in ss) {
4040
if (ss.hasOwnProperty(s)) {
41+
if (s === "displayName") {
42+
result[s] = ss[s];
43+
}
44+
else {
4145
result[s] = (function(impl) {
4246
return function() {
4347
return impl(this)();
4448
}
4549
})(ss[s]);
50+
}
4651
}
4752
}
4853
result.getInitialState = function() {

Diff for: src/React.purs

+31-29
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
-- | This module defines foreign types and functions which wrap React's functionality.
22

3-
module React
3+
module React
44
( UI()
55
, UIRef()
6-
6+
77
, EventHandler()
8-
8+
99
, Disallowed()
1010
, Read()
1111
, Write()
1212
, Only()
1313
, ReadWrite()
1414
, ReadOnly()
15-
15+
1616
, ReactState()
1717
, ReactProps()
1818
, ReactRefs()
19-
19+
2020
, Refs()
21-
21+
2222
, Render()
23-
23+
2424
, UISpec()
25-
25+
2626
, Event()
2727
, MouseEvent()
2828
, KeyboardEvent()
29-
29+
3030
, EventHandlerContext()
31-
31+
3232
, spec
33-
33+
3434
, getProps
3535
, getRefs
36-
36+
3737
, readState
3838
, writeState
3939
, transformState
40-
40+
4141
, mkUI
42-
42+
4343
, handle
44-
44+
4545
, renderToString
4646
, renderToBody
4747
, renderToElementById
@@ -103,13 +103,13 @@ foreign import data Refs :: *
103103
foreign import data Event :: *
104104

105105
-- | The type of mouse events.
106-
type MouseEvent =
106+
type MouseEvent =
107107
{ pageX :: Number
108-
, pageY :: Number
108+
, pageY :: Number
109109
}
110110

111111
-- | The type of keyboard events.
112-
type KeyboardEvent =
112+
type KeyboardEvent =
113113
{ altKey :: Boolean
114114
, ctrlKey :: Boolean
115115
, charCode :: Int
@@ -124,7 +124,7 @@ type KeyboardEvent =
124124
}
125125

126126
-- | A function which handles events.
127-
type EventHandlerContext eff props state result =
127+
type EventHandlerContext eff props state result =
128128
Eff ( props :: ReactProps props
129129
, refs :: ReactRefs ReadOnly
130130
, state :: ReactState ReadWrite state
@@ -143,6 +143,7 @@ type Render props state eff =
143143
-- | A specification of a component.
144144
type UISpec props state eff =
145145
{ render :: Render props state eff
146+
, displayName :: String
146147
, getInitialState
147148
:: UIRef ->
148149
Eff ( props :: ReactProps props
@@ -205,6 +206,7 @@ type UISpec props state eff =
205206
spec :: forall props state eff. state -> Render props state eff -> UISpec props state eff
206207
spec st render =
207208
{ render: render
209+
, displayName: ""
208210
, getInitialState: \_ -> pure st
209211
, componentWillMount: \_ -> return unit
210212
, componentDidMount: \_ -> return unit
@@ -216,30 +218,30 @@ spec st render =
216218
}
217219

218220
-- | Read the component props.
219-
foreign import getProps :: forall props eff.
220-
UIRef ->
221+
foreign import getProps :: forall props eff.
222+
UIRef ->
221223
Eff (props :: ReactProps props | eff) props
222224

223225
-- | Read the component refs.
224226
foreign import getRefs :: forall write eff.
225-
UIRef ->
227+
UIRef ->
226228
Eff (refs :: ReactRefs (Read write) | eff) Refs
227229

228230
-- | Write the component state.
229-
foreign import writeState :: forall state eff.
230-
UIRef ->
231-
state ->
231+
foreign import writeState :: forall state eff.
232+
UIRef ->
233+
state ->
232234
Eff (state :: ReactState ReadWrite state | eff) state
233235

234236
-- | Read the component state.
235-
foreign import readState :: forall state write eff.
237+
foreign import readState :: forall state write eff.
236238
UIRef ->
237239
Eff (state :: ReactState (Read write) state | eff) state
238240

239241
-- | Transform the component state by applying a function.
240-
transformState :: forall state statePerms eff.
242+
transformState :: forall state statePerms eff.
241243
UIRef ->
242-
(state -> state) ->
244+
(state -> state) ->
243245
Eff (state :: ReactState ReadWrite state | eff) state
244246
transformState ctx f = do
245247
state <- readState ctx
@@ -248,7 +250,7 @@ transformState ctx f = do
248250
-- | Create a component from a component spec.
249251
foreign import mkUI :: forall props state eff.
250252
UISpec props state eff ->
251-
props ->
253+
props ->
252254
UI
253255

254256
-- | Create an event handler.

Diff for: src/React/DOM.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55

66
function mkProps(props) {
77
var result = {};
8-
8+
99
for (var i = 0, len = props.length; i < len; i++) {
1010
var prop = props[i];
11-
11+
1212
for (var key in prop) {
1313
if (prop.hasOwnProperty(key)) {
1414
result[key] = prop[key];
1515
}
1616
}
1717
}
18-
18+
1919
return result;
2020
};
2121

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ foreign import data Props :: *
99
foreign import unsafeMkProps :: forall val. String -> val -> Props
1010

1111
foreign import unsafeUnfoldProps :: forall vals. String -> { | vals } -> Props
12-
12+
1313
aria :: forall ariaAttrs. { | ariaAttrs } -> Props
1414
aria = unsafeUnfoldProps "aria"
1515

@@ -422,4 +422,4 @@ onScroll :: forall eff props state result. (Event -> EventHandlerContext eff pro
422422
onScroll f = unsafeMkProps "onScroll" (handle f)
423423

424424
onWheel :: forall eff props state result. (Event -> EventHandlerContext eff props state result) -> Props
425-
onWheel f = unsafeMkProps "onWheel" (handle f)
425+
onWheel f = unsafeMkProps "onWheel" (handle f)

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module React.DOM.SVG where
2-
2+
33
import React
44
import React.DOM (mkDOM)
55
import React.DOM.Props (Props())
6-
6+
77
circle :: Array Props -> Array UI -> UI
88
circle = mkDOM "circle"
99

@@ -56,4 +56,4 @@ text :: Array Props -> Array UI -> UI
5656
text = mkDOM "text"
5757

5858
tspan :: Array Props -> Array UI -> UI
59-
tspan = mkDOM "tspan"
59+
tspan = mkDOM "tspan"

0 commit comments

Comments
 (0)