Skip to content

Commit 8725c37

Browse files
committed
frp counter example
1 parent d78ea64 commit 8725c37

File tree

5 files changed

+3203
-0
lines changed

5 files changed

+3203
-0
lines changed

examples/frp-counter/bin/compiler.jar

6.09 MB
Binary file not shown.

examples/frp-counter/package.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"name": "mostux-todomvc",
3+
"version": "0.0.1",
4+
"description": "",
5+
"browserify": {
6+
"transform": [
7+
[
8+
"babelify",
9+
{
10+
"extensions": [
11+
".es6",
12+
".jsx",
13+
".js"
14+
]
15+
}
16+
]
17+
]
18+
},
19+
"scripts": {
20+
"build": "NODE_ENV=production browserify src/app.jsx --extension=.jsx --extension=.es6 | java -jar bin/compiler.jar > public/app.js",
21+
"start": "ecstatic -p 8000 public",
22+
"watch": "watchify -d src/app.jsx --extension=.jsx --extension=.es6 -o public/app.js -dv",
23+
"test": "jest"
24+
},
25+
"jest": {
26+
"scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
27+
"testFileExtensions": [
28+
"es6",
29+
"js",
30+
"jsx"
31+
],
32+
"moduleFileExtensions": [
33+
"js",
34+
"json",
35+
"es6",
36+
"jsx"
37+
]
38+
},
39+
"dependencies": {
40+
"ramda": "^0.22.1",
41+
"react": "^15.3.2",
42+
"react-dom": "^15.3.2",
43+
"react-most": "^0.6.5",
44+
"union-type": "^0.3.3"
45+
},
46+
"devDependencies": {
47+
"babel": "^6.5.2",
48+
"babel-jest": "^16.0.0",
49+
"babel-plugin-ramda": "^1.1.6",
50+
"babel-plugin-transform-react-jsx": "^6.1.18",
51+
"babel-preset-es2015": "^6.1.18",
52+
"babelify": "^7.2.0",
53+
"browserify": "^12.0.1",
54+
"ecstatic": "^1.3.1",
55+
"envify": "^3.4.1",
56+
"jest-cli": "^0.7.0",
57+
"react-addons-test-utils": "^15.3.2",
58+
"watchify": "^3.6.1"
59+
},
60+
"author": "Jichao Ouyang",
61+
"license": "ISC",
62+
"babel": {
63+
"presets": [
64+
"es2015"
65+
],
66+
"plugins": [
67+
"transform-react-jsx",
68+
"ramda"
69+
]
70+
}
71+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>Type N Search</title>
7+
<style>
8+
.display {
9+
display: block;
10+
}
11+
.hidden {
12+
display: none;
13+
}
14+
.red {
15+
color: red;
16+
}
17+
</style>
18+
</head>
19+
<body>
20+
<h1>Github Reactive Repo Search</h1>
21+
<div id="app"></div>
22+
<footer class="info">
23+
<p>Created by <a href="https://github.com/jcouyang">Jichao Ouyang</a></p>
24+
<p>a <a href="http://github.com/jcouyang/react-most">React Most</a> Example</p>
25+
</footer>
26+
<script src="app.js"></script>
27+
</body>
28+
</html>

examples/frp-counter/src/app.jsx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React from 'react';
2+
import { render } from 'react-dom';
3+
import Most, { connect } from '../../../lib/react-most'
4+
import {from, lensProp, over, set, inc, dec, identity, compose} from 'ramda'
5+
import Type from 'union-type'
6+
export default Type({
7+
Inc: [Number],
8+
Dec: [Number],
9+
Double: [],
10+
Half: []
11+
})
12+
13+
const CounterView = props => (
14+
<div>
15+
<button onClick={props.actions.half}>/2</button>
16+
<button onClick={()=>props.actions.dec(1)}>-</button>
17+
<span>{props.count}</span>
18+
<button onClick={()=>props.actions.inc(1)}>+</button>
19+
<button onClick={props.actions.double}>*2</button>
20+
</div>
21+
)
22+
23+
CounterView.defaultProps = { count: 0 };
24+
25+
const lensCount = lensProp('count')
26+
27+
const doublable = connect(intent$ => {
28+
return {
29+
sink$: intent$.map(Intent.case({
30+
Double: () => over(lensCount, x=>x*2),
31+
Half: () => over(lensCount, x=>x/2),
32+
_: () => identity
33+
})),
34+
actions: {
35+
double: Intent.Double,
36+
half: Intent.Half,
37+
}
38+
}
39+
})
40+
41+
const increasable = connect(intent$ => {
42+
return {
43+
sink$: intent$.map(Intent.case({
44+
Inc: (v) => over(lensCount, inc(v)),
45+
Dec: (v) => over(lensCount, dec(v)),
46+
_: () => identity
47+
})),
48+
actions: {
49+
inc: Intent.Inc,
50+
dec: Intent.Dec,
51+
}
52+
}
53+
})
54+
55+
const Counter = doublable(increasable(CounterView))
56+
57+
render(
58+
<Most>
59+
<Counter />
60+
</Most>
61+
, document.getElementById('app'));

0 commit comments

Comments
 (0)