Skip to content

Commit 3d68e37

Browse files
author
Phil Freeman
committed
Initial create
1 parent f0638e9 commit 3d68e37

File tree

8 files changed

+1933
-0
lines changed

8 files changed

+1933
-0
lines changed

Diff for: .gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/bower_components/
2+
/node_modules/
3+
/.pulp-cache/
4+
/output/
5+
/generated-docs/
6+
/.psc-package/
7+
/.psc*
8+
/.purs*
9+
/.psa*

Diff for: bower.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "purescript-react-basic",
3+
"ignore": [
4+
"**/.*",
5+
"node_modules",
6+
"bower_components",
7+
"output"
8+
],
9+
"dependencies": {
10+
"purescript-functions": "^3.0.0",
11+
"purescript-eff": "^3.1.0",
12+
"purescript-unsafe-coerce": "^3.0.0"
13+
}
14+
}

Diff for: src/React/Basic.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"use strict";
2+
3+
var React = require('react');
4+
5+
exports.react_ = function(spec) {
6+
return React.createClass({
7+
getInitialState: function() {
8+
return spec.initialState;
9+
},
10+
render: function() {
11+
var this_ = this;
12+
return spec.render(this.props, this.state, function(newState) {
13+
return function() {
14+
this_.setState(newState);
15+
};
16+
});
17+
}
18+
});
19+
};

Diff for: src/React/Basic.purs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module React.Basic
2+
( react
3+
, module React.Basic.DOM
4+
, module React.Basic.Types
5+
) where
6+
7+
import Prelude
8+
9+
import Control.Monad.Eff (Eff, kind Effect)
10+
import Data.Function.Uncurried (Fn3, mkFn3)
11+
import React.Basic.DOM as React.Basic.DOM
12+
import React.Basic.Types (CSS, EventHandler, JSX, ReactComponent, ReactFX)
13+
import React.Basic.Types as React.Basic.Types
14+
15+
foreign import react_
16+
:: forall props state
17+
. { initialState :: state
18+
, render :: Fn3 props state (state -> Eff (react :: ReactFX) Unit) JSX
19+
}
20+
-> ReactComponent props
21+
22+
-- | Create a React component from a _specification_ of that component.
23+
-- |
24+
-- | A _specification_ consists of a state type, an initial value for that state,
25+
-- | and a rendering function which takes a value of that state type, additional
26+
-- | _props_ (which will be passed in by the user) and a state update function.
27+
-- |
28+
-- | The rendering function should return a value of type `JSX`, which can be
29+
-- | constructed using the helper functions provided by the `React.Basic.DOM`
30+
-- | module (and re-exported here).
31+
react
32+
:: forall props state
33+
. { initialState :: state
34+
, render :: props -> state -> (state -> Eff (react :: ReactFX) Unit) -> JSX
35+
}
36+
-> ReactComponent props
37+
react { initialState, render } = react_ { initialState, render: mkFn3 render }

0 commit comments

Comments
 (0)