-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from jayphelps/rename-files
Tweak docs, add example app
- Loading branch information
Showing
15 changed files
with
226 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"presets": ["es2015", "react"], | ||
"plugins": [ | ||
"transform-object-rest-spread" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Basic Example | ||
|
||
### Run it | ||
|
||
```bash | ||
npm install | ||
npm start | ||
# Listening at localhost:3000 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<html> | ||
<head> | ||
<title>Example</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script src="/static/bundle.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "redux-observable-example-basic", | ||
"version": "1.0.0", | ||
"description": "Example usage of redux-observable", | ||
"main": "server.js", | ||
"scripts": { | ||
"start": "node server.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/blesh/redux-observable.git" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"dependencies": { | ||
"babel-runtime": "^6.6.1", | ||
"react": "^15.0.2", | ||
"react-dom": "^15.0.2", | ||
"react-redux": "^4.4.5", | ||
"redux": "^3.5.2", | ||
"redux-observable": "*", | ||
"rxjs": "^5.0.0-beta.7" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.7.7", | ||
"babel-core": "^6.7.7", | ||
"babel-loader": "^6.2.4", | ||
"babel-plugin-transform-object-rest-spread": "^6.8.0", | ||
"babel-preset-es2015": "^6.6.0", | ||
"babel-preset-react": "^6.5.0", | ||
"node-libs-browser": "^0.5.2", | ||
"react-hot-loader": "^1.2.7", | ||
"webpack": "^1.9.11", | ||
"webpack-dev-server": "^1.9.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var webpack = require('webpack'); | ||
var WebpackDevServer = require('webpack-dev-server'); | ||
var config = require('./webpack.config'); | ||
|
||
new WebpackDevServer(webpack(config), { | ||
publicPath: config.output.publicPath, | ||
hot: true, | ||
historyApiFallback: true, | ||
stats: { colors: true } | ||
}).listen(3000, 'localhost', function (err) { | ||
if (err) { | ||
console.log(err); | ||
} | ||
|
||
console.log('Listening at localhost:3000'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as Rx from 'rxjs'; | ||
|
||
export const FETCH_USER_PENDING = 'FETCH_USER_PENDING'; | ||
export const FETCH_USER_FULFILLED = 'FETCH_USER_FULFILLED'; | ||
export const FETCH_USER_ABORTED = 'FETCH_USER_ABORTED'; | ||
|
||
export const fetchUser = () => ( | ||
(actions, store) => Rx.Observable.of({ id: 1, name: 'Bilbo Baggins', timestamp: new Date() }) | ||
// Delaying to emulate an async request, like Rx.Observable.ajax('/api/path') | ||
.delay(1000) | ||
// When our request comes back, we transform it into an action | ||
// that is then automatically dispatched by the middleware | ||
.map( | ||
payload => ({ type: FETCH_USER_FULFILLED, payload }) | ||
) | ||
// Abort fetching the user if someone dispatches an abort action | ||
.takeUntil( | ||
actions.filter(action => action.type === FETCH_USER_ABORTED) | ||
) | ||
// Let's us immediately update the user's state so we can display | ||
// loading messages to the user, etc. | ||
.startWith({ type: FETCH_USER_PENDING }) | ||
); | ||
|
||
// Plain old action | ||
export const abortFetchUser = () => ({ type: FETCH_USER_ABORTED }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { fetchUser, abortFetchUser } from '../actions'; | ||
|
||
const Example = ({ user, fetchUser, abortFetchUser }) => ( | ||
<div> | ||
<button onClick={fetchUser}>fetch user</button> | ||
<button onClick={abortFetchUser}>abort fetch user</button> | ||
<div>Loading: {`${user.isLoading}`}</div> | ||
<pre>{JSON.stringify(user, null, 2)}</pre> | ||
</div> | ||
); | ||
|
||
const mapStateToProps = ({ user }) => ({ user }); | ||
|
||
const mapDispatchToProps = (dispatch) => ({ | ||
fetchUser: () => dispatch(fetchUser()), | ||
abortFetchUser: () => dispatch(abortFetchUser()) | ||
}); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(Example); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import { render } from 'react-dom'; | ||
import { createStore, applyMiddleware } from 'redux'; | ||
import { Provider } from 'react-redux'; | ||
import { reduxObservable } from 'redux-observable'; | ||
import rootReducer from './reducers'; | ||
import Example from './components/Example'; | ||
|
||
const store = createStore(rootReducer, applyMiddleware(reduxObservable())); | ||
|
||
render( | ||
<Provider store={store}> | ||
<Example /> | ||
</Provider>, | ||
document.getElementById('app') | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { combineReducers } from 'redux'; | ||
import { FETCH_USER_PENDING, FETCH_USER_FULFILLED, FETCH_USER_ABORTED } from '../actions'; | ||
|
||
const user = (state = { isLoading: false }, action) => { | ||
switch (action.type) { | ||
case FETCH_USER_PENDING: | ||
return { ...state, isLoading: true }; | ||
|
||
case FETCH_USER_FULFILLED: | ||
return { ...state, isLoading: false, ...action.payload }; | ||
|
||
case FETCH_USER_ABORTED: | ||
return { ...state, isLoading: false }; | ||
|
||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default combineReducers({ user }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var path = require('path'); | ||
var webpack = require('webpack'); | ||
|
||
module.exports = { | ||
devtool: 'eval', | ||
entry: [ | ||
'webpack-dev-server/client?http://localhost:3000', | ||
'webpack/hot/only-dev-server', | ||
'./src/index' | ||
], | ||
output: { | ||
path: path.join(__dirname, 'dist'), | ||
filename: 'bundle.js', | ||
publicPath: '/static/' | ||
}, | ||
plugins: [ | ||
new webpack.HotModuleReplacementPlugin(), | ||
new webpack.NoErrorsPlugin() | ||
], | ||
resolve: { | ||
extensions: ['', '.js'] | ||
}, | ||
module: { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loaders: ['react-hot', 'babel'], | ||
exclude: /node_modules/, | ||
include: __dirname | ||
}, { | ||
test: /\.js$/, | ||
loaders: ['babel'], | ||
include: path.join(__dirname, '..', '..', 'src') | ||
}] | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.