Skip to content

Add utility functions #37

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 2 commits into from
May 16, 2018
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
14 changes: 14 additions & 0 deletions generated-docs/React/Basic/DOM.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ E.g.
div { style: css { padding: "5px" } } [ text "This text is padded." ]
```

#### `mergeStyles`

``` purescript
mergeStyles :: Array CSS -> CSS
```

Merge styles from right to left. Uses `Object.assign`.

E.g.

```
style: mergeCSS [ (css { padding: "5px" }), props.style ]
```

#### `SharedProps`

``` purescript
Expand Down
6 changes: 6 additions & 0 deletions generated-docs/React/Basic/Events.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ input { onChange: handler_ (setState \_ -> { value })
}
```

#### `syntheticEvent`

``` purescript
syntheticEvent :: EventFn SyntheticEvent SyntheticEvent
```

#### `merge`

``` purescript
Expand Down
5 changes: 5 additions & 0 deletions src/React/Basic/DOM.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

exports.mergeStyles = function(styles) {
return Object.assign.apply(null, [ {} ].concat(styles));
};
9 changes: 9 additions & 0 deletions src/React/Basic/DOM.purs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ foreign import data CSS :: Type
css :: forall css. { | css } -> CSS
css = unsafeCoerce

-- | Merge styles from right to left. Uses `Object.assign`.
-- |
-- | E.g.
-- |
-- | ```
-- | style: mergeCSS [ (css { padding: "5px" }), props.style ]
-- | ```
foreign import mergeStyles :: Array CSS -> CSS

-- | Standard props which are shared by all DOM elements.
type SharedProps specific =
-- | `key` is not really a DOM attribute - React intercepts it
Expand Down
4 changes: 4 additions & 0 deletions src/React/Basic/Events.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module React.Basic.Events
, unsafeEventFn
, handler
, handler_
, syntheticEvent
, merge
, class Merge
, mergeImpl
Expand Down Expand Up @@ -72,6 +73,9 @@ handler (EventFn fn) cb = mkEffFn1 $ fn >>> cb
handler_ :: Eff (react :: ReactFX) Unit -> EventHandler
handler_ = mkEffFn1 <<< const

syntheticEvent :: EventFn SyntheticEvent SyntheticEvent
syntheticEvent = id

class Merge (rl :: RowList) fns a r | rl -> fns, rl a -> r where
mergeImpl :: RLProxy rl -> Record fns -> EventFn a (Record r)

Expand Down