Skip to content

Commit 7c2c705

Browse files
committed
Add example
1 parent 6a13f15 commit 7c2c705

File tree

6 files changed

+69
-2
lines changed

6 files changed

+69
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ node_modules
3333
.node_repl_history
3434

3535
/lib
36+
/demo/bundle.*

demo/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<html>
2+
<head>
3+
<meta charset="UTF-8">
4+
<title>React + Redux + Routility Demo</title>
5+
</head>
6+
<body>
7+
<div id="app"></div>
8+
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/4.0.8/rx.all.js"></script>
9+
<script src="https://npmcdn.com/redux@latest/dist/redux.js"></script>
10+
<script src="bundle.js"></script>
11+
</body>
12+
</html>

demo/script.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import observableMiddleware from '../src/index';
2+
3+
const ACTION_TYPE = 'INTERVAL';
4+
5+
function reducer(state = null, action) {
6+
console.log(action);
7+
switch (action.type) {
8+
case `${ACTION_TYPE}_ON_NEXT`:
9+
return action.data;
10+
case `${ACTION_TYPE}_ON_ERROR`:
11+
return state;
12+
case `${ACTION_TYPE}_ON_COMPLETED`:
13+
return state;
14+
default:
15+
return state;
16+
}
17+
}
18+
19+
const store = Redux.createStore(reducer, Redux.applyMiddleware(observableMiddleware));
20+
21+
store.subscribe(() => {
22+
console.log(store.getState());
23+
});
24+
25+
store.dispatch({
26+
type: ACTION_TYPE,
27+
observable: Rx.Observable.interval(1000).take(5),
28+
});

demo/webpack.config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
const join = require('path').join;
4+
5+
module.exports = {
6+
entry: join(__dirname, 'script.js'),
7+
8+
output: {
9+
filename: 'bundle.js',
10+
path: __dirname
11+
},
12+
13+
devtool: 'source-map',
14+
15+
module: {
16+
loaders: [
17+
{
18+
test: /\.js$/,
19+
exclude: /node_modules/,
20+
loader: 'babel',
21+
}
22+
]
23+
}
24+
};

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
"devDependencies": {
2222
"babel-cli": "^6.5.1",
2323
"babel-core": "^6.5.2",
24+
"babel-loader": "^6.2.3",
2425
"babel-preset-es2015": "^6.5.0",
25-
"rimraf": "^2.5.2"
26+
"rimraf": "^2.5.2",
27+
"webpack": "^1.12.14"
2628
},
2729
"scripts": {
2830
"clean": "rimraf lib",

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ function observableMiddleware({ dispatch, getState }) {
33
if (action.observable != null &&
44
typeof action.observable.subscribe === 'function')
55
{
6-
observable.subscribe(
6+
action.observable.subscribe(
77
function onNext(data) {
88
dispatch({ type: `${action.type}_ON_NEXT`, data });
99
},

0 commit comments

Comments
 (0)