From d385e5bea9113aa75fcc1f498fbfd23654f6254b Mon Sep 17 00:00:00 2001 From: eric thul Date: Fri, 16 Oct 2015 23:52:08 -0400 Subject: [PATCH] Adds a spec constructor function with getInitialState --- docs/React.md | 10 +++++++++- src/React.purs | 28 ++++++++++++++++------------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/docs/React.md b/docs/React.md index 518696a..27b9177 100644 --- a/docs/React.md +++ b/docs/React.md @@ -230,7 +230,15 @@ A specification of a component. spec :: forall props state eff. state -> Render props state eff -> ReactSpec props state eff ``` -Create a component specification. +Create a component specification with a provided state. + +#### `spec'` + +``` purescript +spec' :: forall props state eff. GetInitialState props state eff -> Render props state eff -> ReactSpec props state eff +``` + +Create a component specification with a get initial state function. #### `ReactClass` diff --git a/src/React.purs b/src/React.purs index a3c3841..cfc0dea 100644 --- a/src/React.purs +++ b/src/React.purs @@ -38,7 +38,7 @@ module React , EventHandlerContext() - , spec + , spec, spec' , getProps , getRefs @@ -244,19 +244,23 @@ type ReactSpec props state eff = , componentWillUnmount :: ComponentWillUnmount props state eff } --- | Create a component specification. +-- | Create a component specification with a provided state. spec :: forall props state eff. state -> Render props state eff -> ReactSpec props state eff -spec st renderFn = - { render: renderFn - , displayName: "" - , getInitialState: \_ -> pure st - , componentWillMount: \_ -> return unit - , componentDidMount: \_ -> return unit +spec state = spec' (\_ -> pure state) + +-- | Create a component specification with a get initial state function. +spec' :: forall props state eff. GetInitialState props state eff -> Render props state eff -> ReactSpec props state eff +spec' getInitialState renderFn = + { render: renderFn + , displayName: "" + , getInitialState: getInitialState + , componentWillMount: \_ -> return unit + , componentDidMount: \_ -> return unit , componentWillReceiveProps: \_ _ -> return unit - , shouldComponentUpdate: \_ _ _ -> return true - , componentWillUpdate: \_ _ _ -> return unit - , componentDidUpdate: \_ _ _ -> return unit - , componentWillUnmount: \_ -> return unit + , shouldComponentUpdate: \_ _ _ -> return true + , componentWillUpdate: \_ _ _ -> return unit + , componentDidUpdate: \_ _ _ -> return unit + , componentWillUnmount: \_ -> return unit } -- | React class for components.