Skip to content

Commit e69bed7

Browse files
committed
Add reason version of HelloWorld
1 parent 0de320e commit e69bed7

File tree

11 files changed

+126
-79
lines changed

11 files changed

+126
-79
lines changed

.atom/ide-reason.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"path": {
3+
"bsb": "./node_modules/.bin/bsb",
4+
"bsc": "./node_modules/.bin/bsc"
5+
}
6+
}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@
2222
/node_modules
2323
yarn-debug.log*
2424
.yarn-integrity
25+
26+
lib/bs/
27+
.merlin
28+
.bsb.lock
29+
*.bs.js

README.md

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
1-
# README
1+
# reason-react-on-rails-example
22

3-
This README would normally document whatever steps are necessary to get the
4-
application up and running.
5-
6-
Things you may want to cover:
7-
8-
* Ruby version
9-
10-
* System dependencies
11-
12-
* Configuration
13-
14-
* Database creation
15-
16-
* Database initialization
17-
18-
* How to run the test suite
19-
20-
* Services (job queues, cache servers, search engines, etc.)
21-
22-
* Deployment instructions
23-
24-
* ...
3+
```shell
4+
docker-compose build
5+
docker-compose run web yarn run build
6+
docker-compose up
7+
```

app/javascript/Utils.re

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
let eventTargetValue = event => {
2+
let target = event |> ReactEventRe.Form.target;
3+
ReactDOMRe.domElementToObj(target)##value;
4+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
type state = {name: string};
2+
3+
type action =
4+
| UpdateName(string);
5+
6+
let component = ReasonReact.reducerComponent(__MODULE__);
7+
8+
let make = (~name: string, _) => {
9+
...component,
10+
initialState: () => {name: name},
11+
reducer: (action, _state) =>
12+
switch (action) {
13+
| UpdateName(name) => ReasonReact.Update({name: name})
14+
},
15+
render: ({state, send}) =>
16+
<div>
17+
<h3>
18+
("Hello, " ++ state.name ++ "!" |> ReasonReact.stringToElement)
19+
</h3>
20+
<hr />
21+
<form>
22+
<label htmlFor="name">
23+
("Say hello to:" |> ReasonReact.stringToElement)
24+
</label>
25+
<input
26+
id="name"
27+
_type="text"
28+
value=state.name
29+
onChange=(
30+
event => UpdateName(event |> Utils.eventTargetValue) |> send
31+
)
32+
/>
33+
</form>
34+
</div>,
35+
};

app/javascript/bundles/HelloWorld/components/HelloWorld.jsx

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
type props = {. "name": string};
2+
3+
type context = {
4+
.
5+
"host": string,
6+
"href": string,
7+
"httpAcceptLanguage": string,
8+
"i18nDefaultLocale": string,
9+
"i18nLocale": string,
10+
"inMailer": Js.boolean,
11+
"location": string,
12+
"pathname": string,
13+
"port": int,
14+
"scheme": string,
15+
"search": Js.nullable(string),
16+
"serverSide": Js.boolean,
17+
};
18+
19+
let component = (props: props, _context: context) =>
20+
<HelloWorld name=props##name />;
21+
22+
ReactOnRails.register("HelloWorld", component);
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
import ReactOnRails from 'react-on-rails';
2-
3-
import HelloWorld from '../bundles/HelloWorld/components/HelloWorld';
4-
5-
// This is how react_on_rails can see the HelloWorld in the browser.
6-
ReactOnRails.register({
7-
HelloWorld,
8-
});
1+
import './HelloWorldBundle.bs.js';

bsconfig.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "app",
3+
"sources": [
4+
{
5+
"dir": "app/javascript",
6+
"subdirs": true
7+
}
8+
],
9+
"bs-dependencies": [
10+
"reason-react",
11+
"bs-react-on-rails"
12+
],
13+
"reason": {
14+
"react-jsx": 2
15+
},
16+
"refmt": 3,
17+
"bsc-flags": ["-bs-super-errors"],
18+
"suffix": ".bs.js",
19+
"package-specs": {
20+
"module": "commonjs",
21+
"in-source": true
22+
}
23+
}

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
{
22
"name": "app",
33
"private": true,
4+
"scripts": {
5+
"build": "bsb -clean-world -make-world"
6+
},
47
"dependencies": {
58
"@rails/webpacker": "^3.4.1",
69
"babel-preset-react": "^6.24.1",
10+
"bs-react-on-rails": "^0.0.1",
711
"prop-types": "^15.6.1",
812
"react": "^16.2.0",
913
"react-dom": "^16.2.0",
10-
"react-on-rails": "^10.1.3"
14+
"react-on-rails": "^10.1.3",
15+
"reason-react": "^0.3.4"
1116
},
1217
"devDependencies": {
18+
"bs-platform": "^2.2.3",
1319
"webpack-dev-server": "2.11.2"
1420
}
1521
}

0 commit comments

Comments
 (0)