Skip to content

Commit 6a13f15

Browse files
committed
Init implementation
1 parent ef5265f commit 6a13f15

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

Diff for: .babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015"]
3+
}

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ node_modules
3131

3232
# Optional REPL history
3333
.node_repl_history
34+
35+
/lib

Diff for: package.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "redux-observable-middleware",
3+
"version": "0.0.0",
4+
"description": "",
5+
"main": "./lib/index.js",
6+
"files": [
7+
"lib",
8+
"src"
9+
],
10+
"repository": {
11+
"type": "git",
12+
"url": "git+https://github.com/d6u/redux-observable-middleware.git"
13+
},
14+
"author": "Daiwei Lu <[email protected]> (http://daiwei.lu)",
15+
"license": "MIT",
16+
"bugs": {
17+
"url": "https://github.com/d6u/redux-observable-middleware/issues"
18+
},
19+
"homepage": "https://github.com/d6u/redux-observable-middleware#readme",
20+
"dependencies": {},
21+
"devDependencies": {
22+
"babel-cli": "^6.5.1",
23+
"babel-core": "^6.5.2",
24+
"babel-preset-es2015": "^6.5.0",
25+
"rimraf": "^2.5.2"
26+
},
27+
"scripts": {
28+
"clean": "rimraf lib",
29+
"build:lib": "babel src --out-dir lib",
30+
"build": "npm run build:lib",
31+
"preversion": "npm run check",
32+
"postversion": "git push && git push --tags",
33+
"prepublish": "npm run clean && npm run build"
34+
}
35+
}

Diff for: src/index.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function observableMiddleware({ dispatch, getState }) {
2+
return (next) => (action) => {
3+
if (action.observable != null &&
4+
typeof action.observable.subscribe === 'function')
5+
{
6+
observable.subscribe(
7+
function onNext(data) {
8+
dispatch({ type: `${action.type}_ON_NEXT`, data });
9+
},
10+
function onError(err) {
11+
dispatch({ type: `${action.type}_ON_ERROR`, err });
12+
},
13+
function onCompleted() {
14+
dispatch({ type: `${action.type}_ON_COMPLETED` });
15+
}
16+
);
17+
}
18+
19+
next(action);
20+
}
21+
}
22+
23+
module.exports = observableMiddleware;

0 commit comments

Comments
 (0)