Skip to content

Adding type synonyms for lifecycle functions #46

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 66 additions & 2 deletions docs/React.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,76 @@ A function which handles events.
type Render props state eff = ReactThis props state -> Eff (props :: ReactProps props, refs :: ReactRefs Disallowed, state :: ReactState ReadOnly state | eff) ReactElement
```

A rendering function.
A render function.

#### `GetInitialState`

``` purescript
type GetInitialState props state eff = ReactThis props state -> Eff (props :: ReactProps props, state :: ReactState Disallowed state, refs :: ReactRefs Disallowed | eff) state
```

A get initial state function.

#### `ComponentWillMount`

``` purescript
type ComponentWillMount props state eff = ReactThis props state -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs Disallowed | eff) Unit
```

A component will mount function.

#### `ComponentDidMount`

``` purescript
type ComponentDidMount props state eff = ReactThis props state -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit
```

A component did mount function.

#### `ComponentWillReceiveProps`

``` purescript
type ComponentWillReceiveProps props state eff = ReactThis props state -> props -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit
```

A component will receive props function.

#### `ShouldComponentUpdate`

``` purescript
type ShouldComponentUpdate props state eff = ReactThis props state -> props -> state -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Boolean
```

A should component update function.

#### `ComponentWillUpdate`

``` purescript
type ComponentWillUpdate props state eff = ReactThis props state -> props -> state -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit
```

A component will update function.

#### `ComponentDidUpdate`

``` purescript
type ComponentDidUpdate props state eff = ReactThis props state -> props -> state -> Eff (props :: ReactProps props, state :: ReactState ReadOnly state, refs :: ReactRefs ReadOnly | eff) Unit
```

A component did update function.

#### `ComponentWillUnmount`

``` purescript
type ComponentWillUnmount props state eff = ReactThis props state -> Eff (props :: ReactProps props, state :: ReactState ReadOnly state, refs :: ReactRefs ReadOnly | eff) Unit
```

A component will unmount function.

#### `ReactSpec`

``` purescript
type ReactSpec props state eff = { render :: Render props state eff, displayName :: String, getInitialState :: ReactThis props state -> Eff (props :: ReactProps props, state :: ReactState Disallowed state, refs :: ReactRefs Disallowed | eff) state, componentWillMount :: ReactThis props state -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs Disallowed | eff) Unit, componentDidMount :: ReactThis props state -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit, componentWillReceiveProps :: ReactThis props state -> props -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit, shouldComponentUpdate :: ReactThis props state -> props -> state -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Boolean, componentWillUpdate :: ReactThis props state -> props -> state -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit, componentDidUpdate :: ReactThis props state -> props -> state -> Eff (props :: ReactProps props, state :: ReactState ReadOnly state, refs :: ReactRefs ReadOnly | eff) Unit, componentWillUnmount :: ReactThis props state -> Eff (props :: ReactProps props, state :: ReactState ReadOnly state, refs :: ReactRefs ReadOnly | eff) Unit }
type ReactSpec props state eff = { render :: Render props state eff, displayName :: String, getInitialState :: GetInitialState props state eff, componentWillMount :: ComponentWillMount props state eff, componentDidMount :: ComponentDidMount props state eff, componentWillReceiveProps :: ComponentWillReceiveProps props state eff, shouldComponentUpdate :: ShouldComponentUpdate props state eff, componentWillUpdate :: ComponentWillUpdate props state eff, componentDidUpdate :: ComponentDidUpdate props state eff, componentWillUnmount :: ComponentWillUnmount props state eff }
```

A specification of a component.
Expand Down
160 changes: 96 additions & 64 deletions src/React.purs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ module React
, Refs()

, Render()
, GetInitialState()
, ComponentWillMount()
, ComponentDidMount()
, ComponentWillReceiveProps()
, ShouldComponentUpdate()
, ComponentWillUpdate()
, ComponentDidUpdate()
, ComponentWillUnmount()

, ReactSpec()
, ReactClass()
Expand Down Expand Up @@ -134,7 +142,7 @@ type EventHandlerContext eff props state result =
| eff
) result

-- | A rendering function.
-- | A render function.
type Render props state eff =
ReactThis props state ->
Eff ( props :: ReactProps props
Expand All @@ -143,73 +151,97 @@ type Render props state eff =
| eff
) ReactElement

-- | A get initial state function.
type GetInitialState props state eff =
ReactThis props state ->
Eff ( props :: ReactProps props
, state :: ReactState Disallowed state
, refs :: ReactRefs Disallowed
| eff
) state

-- | A component will mount function.
type ComponentWillMount props state eff =
ReactThis props state ->
Eff ( props :: ReactProps props
, state :: ReactState ReadWrite state
, refs :: ReactRefs Disallowed
| eff
) Unit

-- | A component did mount function.
type ComponentDidMount props state eff =
ReactThis props state ->
Eff ( props :: ReactProps props
, state :: ReactState ReadWrite state
, refs :: ReactRefs ReadOnly
| eff
) Unit

-- | A component will receive props function.
type ComponentWillReceiveProps props state eff =
ReactThis props state ->
props ->
Eff ( props :: ReactProps props
, state :: ReactState ReadWrite state
, refs :: ReactRefs ReadOnly
| eff
) Unit

-- | A should component update function.
type ShouldComponentUpdate props state eff =
ReactThis props state ->
props ->
state ->
Eff ( props :: ReactProps props
, state :: ReactState ReadWrite state
, refs :: ReactRefs ReadOnly
| eff
) Boolean

-- | A component will update function.
type ComponentWillUpdate props state eff =
ReactThis props state ->
props ->
state ->
Eff ( props :: ReactProps props
, state :: ReactState ReadWrite state
, refs :: ReactRefs ReadOnly
| eff
) Unit

-- | A component did update function.
type ComponentDidUpdate props state eff =
ReactThis props state ->
props ->
state ->
Eff ( props :: ReactProps props
, state :: ReactState ReadOnly state
, refs :: ReactRefs ReadOnly
| eff
) Unit

-- | A component will unmount function.
type ComponentWillUnmount props state eff =
ReactThis props state ->
Eff ( props :: ReactProps props
, state :: ReactState ReadOnly state
, refs :: ReactRefs ReadOnly
| eff
) Unit

-- | A specification of a component.
type ReactSpec props state eff =
{ render :: Render props state eff
, displayName :: String
, getInitialState
:: ReactThis props state ->
Eff ( props :: ReactProps props
, state :: ReactState Disallowed state
, refs :: ReactRefs Disallowed
| eff
) state
, componentWillMount
:: ReactThis props state ->
Eff ( props :: ReactProps props
, state :: ReactState ReadWrite state
, refs :: ReactRefs Disallowed
| eff
) Unit
, componentDidMount
:: ReactThis props state ->
Eff ( props :: ReactProps props
, state :: ReactState ReadWrite state
, refs :: ReactRefs ReadOnly
| eff
) Unit
, componentWillReceiveProps
:: ReactThis props state ->
props ->
Eff ( props :: ReactProps props
, state :: ReactState ReadWrite state
, refs :: ReactRefs ReadOnly
| eff
) Unit
, shouldComponentUpdate
:: ReactThis props state ->
props ->
state ->
Eff ( props :: ReactProps props
, state :: ReactState ReadWrite state
, refs :: ReactRefs ReadOnly
| eff
) Boolean
, componentWillUpdate
:: ReactThis props state ->
props ->
state ->
Eff ( props :: ReactProps props
, state :: ReactState ReadWrite state
, refs :: ReactRefs ReadOnly
| eff
) Unit
, componentDidUpdate
:: ReactThis props state ->
props ->
state ->
Eff ( props :: ReactProps props
, state :: ReactState ReadOnly state
, refs :: ReactRefs ReadOnly
| eff
) Unit
, componentWillUnmount
:: ReactThis props state ->
Eff ( props :: ReactProps props
, state :: ReactState ReadOnly state
, refs :: ReactRefs ReadOnly
| eff
) Unit
, getInitialState :: GetInitialState props state eff
, componentWillMount :: ComponentWillMount props state eff
, componentDidMount :: ComponentDidMount props state eff
, componentWillReceiveProps :: ComponentWillReceiveProps props state eff
, shouldComponentUpdate :: ShouldComponentUpdate props state eff
, componentWillUpdate :: ComponentWillUpdate props state eff
, componentDidUpdate :: ComponentDidUpdate props state eff
, componentWillUnmount :: ComponentWillUnmount props state eff
}

-- | Create a component specification.
Expand Down