Skip to content

Commit

Permalink
Merge pull request #70 from doolse/wrap-function
Browse files Browse the repository at this point in the history
additional createReactSpec' for custom wrapping
  • Loading branch information
paf31 authored Nov 29, 2016
2 parents 9008e3a + 9c94577 commit 05ec5a1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
14 changes: 14 additions & 0 deletions docs/Thermite.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@ This function is a low-level alternative to `createClass`, used when the React
component spec needs to be modified before being turned into a component class,
e.g. by adding additional lifecycle methods.

#### `createReactSpec'`

``` purescript
createReactSpec' :: forall eff state props action. (Array ReactElement -> ReactElement) -> Spec eff state props action -> state -> { spec :: ReactSpec props state eff, dispatcher :: ReactThis props state -> action -> EventHandler }
```

Create a React component spec from a Thermite component `Spec` with an additional
function for converting the rendered Array of ReactElement's into a single ReactElement
as is required by React.

This function is a low-level alternative to `createClass`, used when the React
component spec needs to be modified before being turned into a component class,
e.g. by adding additional lifecycle methods.

#### `withState`

``` purescript
Expand Down
22 changes: 20 additions & 2 deletions src/Thermite.purs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module Thermite
, simpleSpec
, createClass
, createReactSpec
, createReactSpec'
, withState
, focus
, focusState
Expand Down Expand Up @@ -198,7 +199,24 @@ createReactSpec
-> { spec :: React.ReactSpec props state eff
, dispatcher :: React.ReactThis props state -> action -> EventHandler
}
createReactSpec (Spec spec) state =
createReactSpec = createReactSpec' div'

-- | Create a React component spec from a Thermite component `Spec` with an additional
-- | function for converting the rendered Array of ReactElement's into a single ReactElement
-- | as is required by React.
-- |
-- | This function is a low-level alternative to `createClass`, used when the React
-- | component spec needs to be modified before being turned into a component class,
-- | e.g. by adding additional lifecycle methods.
createReactSpec'
:: forall eff state props action
. (Array React.ReactElement -> React.ReactElement)
-> Spec eff state props action
-> state
-> { spec :: React.ReactSpec props state eff
, dispatcher :: React.ReactThis props state -> action -> EventHandler
}
createReactSpec' wrap (Spec spec) state =
{ spec: React.spec state render
, dispatcher
}
Expand Down Expand Up @@ -226,7 +244,7 @@ createReactSpec (Spec spec) state =
unsafeCoerceEff (launchAff (runProcess process))

render :: React.Render props state eff
render this = map div' $
render this = map wrap $
spec.render (dispatcher this)
<$> React.getProps this
<*> React.readState this
Expand Down

0 comments on commit 05ec5a1

Please sign in to comment.