From 218a672eca3bec02ede3224b5cd2ce2495ae9c41 Mon Sep 17 00:00:00 2001 From: eric thul Date: Tue, 11 Aug 2015 21:54:13 -0400 Subject: [PATCH 1/4] Removing empty spaces --- src/React.purs | 58 ++++++++++++++++++++-------------------- src/React/DOM.js | 6 ++--- src/React/DOM/Props.purs | 4 +-- src/React/DOM/SVG.purs | 6 ++--- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/React.purs b/src/React.purs index 3c03a5e..21225fc 100644 --- a/src/React.purs +++ b/src/React.purs @@ -1,47 +1,47 @@ -- | This module defines foreign types and functions which wrap React's functionality. -module React +module React ( UI() , UIRef() - + , EventHandler() - + , Disallowed() , Read() , Write() , Only() , ReadWrite() , ReadOnly() - + , ReactState() , ReactProps() , ReactRefs() - + , Refs() - + , Render() - + , UISpec() - + , Event() , MouseEvent() , KeyboardEvent() - + , EventHandlerContext() - + , spec - + , getProps , getRefs - + , readState , writeState , transformState - + , mkUI - + , handle - + , renderToString , renderToBody , renderToElementById @@ -103,13 +103,13 @@ foreign import data Refs :: * foreign import data Event :: * -- | The type of mouse events. -type MouseEvent = +type MouseEvent = { pageX :: Number - , pageY :: Number + , pageY :: Number } -- | The type of keyboard events. -type KeyboardEvent = +type KeyboardEvent = { altKey :: Boolean , ctrlKey :: Boolean , charCode :: Int @@ -124,7 +124,7 @@ type KeyboardEvent = } -- | A function which handles events. -type EventHandlerContext eff props state result = +type EventHandlerContext eff props state result = Eff ( props :: ReactProps props , refs :: ReactRefs ReadOnly , state :: ReactState ReadWrite state @@ -216,30 +216,30 @@ spec st render = } -- | Read the component props. -foreign import getProps :: forall props eff. - UIRef -> +foreign import getProps :: forall props eff. + UIRef -> Eff (props :: ReactProps props | eff) props -- | Read the component refs. foreign import getRefs :: forall write eff. - UIRef -> + UIRef -> Eff (refs :: ReactRefs (Read write) | eff) Refs -- | Write the component state. -foreign import writeState :: forall state eff. - UIRef -> - state -> +foreign import writeState :: forall state eff. + UIRef -> + state -> Eff (state :: ReactState ReadWrite state | eff) state -- | Read the component state. -foreign import readState :: forall state write eff. +foreign import readState :: forall state write eff. UIRef -> Eff (state :: ReactState (Read write) state | eff) state -- | Transform the component state by applying a function. -transformState :: forall state statePerms eff. +transformState :: forall state statePerms eff. UIRef -> - (state -> state) -> + (state -> state) -> Eff (state :: ReactState ReadWrite state | eff) state transformState ctx f = do state <- readState ctx @@ -248,7 +248,7 @@ transformState ctx f = do -- | Create a component from a component spec. foreign import mkUI :: forall props state eff. UISpec props state eff -> - props -> + props -> UI -- | Create an event handler. diff --git a/src/React/DOM.js b/src/React/DOM.js index dbcb2b1..25727ad 100644 --- a/src/React/DOM.js +++ b/src/React/DOM.js @@ -5,17 +5,17 @@ function mkProps(props) { var result = {}; - + for (var i = 0, len = props.length; i < len; i++) { var prop = props[i]; - + for (var key in prop) { if (prop.hasOwnProperty(key)) { result[key] = prop[key]; } } } - + return result; }; diff --git a/src/React/DOM/Props.purs b/src/React/DOM/Props.purs index 2cf1bc4..a256141 100644 --- a/src/React/DOM/Props.purs +++ b/src/React/DOM/Props.purs @@ -9,7 +9,7 @@ foreign import data Props :: * foreign import unsafeMkProps :: forall val. String -> val -> Props foreign import unsafeUnfoldProps :: forall vals. String -> { | vals } -> Props - + aria :: forall ariaAttrs. { | ariaAttrs } -> Props aria = unsafeUnfoldProps "aria" @@ -422,4 +422,4 @@ onScroll :: forall eff props state result. (Event -> EventHandlerContext eff pro onScroll f = unsafeMkProps "onScroll" (handle f) onWheel :: forall eff props state result. (Event -> EventHandlerContext eff props state result) -> Props -onWheel f = unsafeMkProps "onWheel" (handle f) \ No newline at end of file +onWheel f = unsafeMkProps "onWheel" (handle f) diff --git a/src/React/DOM/SVG.purs b/src/React/DOM/SVG.purs index 46644d2..339f695 100644 --- a/src/React/DOM/SVG.purs +++ b/src/React/DOM/SVG.purs @@ -1,9 +1,9 @@ module React.DOM.SVG where - + import React import React.DOM (mkDOM) import React.DOM.Props (Props()) - + circle :: Array Props -> Array UI -> UI circle = mkDOM "circle" @@ -56,4 +56,4 @@ text :: Array Props -> Array UI -> UI text = mkDOM "text" tspan :: Array Props -> Array UI -> UI -tspan = mkDOM "tspan" \ No newline at end of file +tspan = mkDOM "tspan" From 82ea9ee0a8f8197df23b8f43c137dda0117a4d1d Mon Sep 17 00:00:00 2001 From: eric thul Date: Tue, 11 Aug 2015 21:55:38 -0400 Subject: [PATCH 2/4] Adding displayName to the spec --- src/React.purs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/React.purs b/src/React.purs index 21225fc..6f4bd5c 100644 --- a/src/React.purs +++ b/src/React.purs @@ -143,6 +143,7 @@ type Render props state eff = -- | A specification of a component. type UISpec props state eff = { render :: Render props state eff + , displayName :: String , getInitialState :: UIRef -> Eff ( props :: ReactProps props @@ -205,6 +206,7 @@ type UISpec props state eff = spec :: forall props state eff. state -> Render props state eff -> UISpec props state eff spec st render = { render: render + , displayName: "" , getInitialState: \_ -> pure st , componentWillMount: \_ -> return unit , componentDidMount: \_ -> return unit From 98778318a41ac6a0a499cfbaa78c6156cb9064cf Mon Sep 17 00:00:00 2001 From: eric thul Date: Tue, 11 Aug 2015 22:09:15 -0400 Subject: [PATCH 3/4] Pass through displayName in FFI --- src/React.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/React.js b/src/React.js index ec770a5..d5b17e5 100644 --- a/src/React.js +++ b/src/React.js @@ -38,11 +38,16 @@ exports.mkUI = function(ss) { var result = {}; for (var s in ss) { if (ss.hasOwnProperty(s)) { + if (s === "displayName") { + result[s] = ss[s]; + } + else { result[s] = (function(impl) { return function() { return impl(this)(); } })(ss[s]); + } } } result.getInitialState = function() { From ac1814ed77aa0279397832e752a84eb9b2981f3e Mon Sep 17 00:00:00 2001 From: eric thul Date: Tue, 11 Aug 2015 22:21:39 -0400 Subject: [PATCH 4/4] Updating module documentation --- docs/React.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/React.md b/docs/React.md index d2c840a..cc41134 100644 --- a/docs/React.md +++ b/docs/React.md @@ -155,7 +155,7 @@ A rendering function. #### `UISpec` ``` purescript -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 } +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 } ``` A specification of a component.