Skip to content

Commit 7296d3c

Browse files
authored
Port examples to use Create React App (#1883)
* Rename examples => examples_old * Port counter and counter-vanilla * Port async example * Port todos example * Port todos-with-undo example * Port some tests over * Add todomvc example * Ported shopping-cart example * Ported tree-view * Ported real-world * Add missing dep * Temp fix install until examples get an equivalent to buildAll.js * Restore example build scripts. * Bump react-scripts * Finish porting examples
1 parent 947e5dd commit 7296d3c

File tree

176 files changed

+823
-1124
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+823
-1124
lines changed

Diff for: examples/async/.babelrc

-8
This file was deleted.

Diff for: examples/async/.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# dependencies
4+
node_modules
5+
6+
# production
7+
build
8+
9+
# misc
10+
.DS_Store
11+
npm-debug.log

Diff for: examples/async/README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Redux Async Example
2+
3+
This project template was built with [Create React App](https://github.com/facebookincubator/create-react-app).
4+
5+
## Available Scripts
6+
7+
In the project directory, you can run:
8+
9+
### `npm start`
10+
11+
Runs the app in the development mode.<br>
12+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
13+
14+
The page will reload if you make edits.<br>
15+
You will also see any lint errors in the console.
16+
17+
### `npm run build`
18+
19+
Builds the app for production to the `build` folder.<br>
20+
It correctly bundles React in production mode and optimizes the build for the best performance.
21+
22+
The build is minified and the filenames include the hashes.<br>
23+
Your app is ready to be deployed!
24+
25+
### `npm run eject`
26+
27+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
28+
29+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
30+
31+
Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
32+
33+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
34+

Diff for: examples/async/index.html

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
<!DOCTYPE html>
2-
<html>
1+
<!doctype html>
2+
<html lang="en">
33
<head>
4-
<title>Redux async example</title>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>Redux Async Example</title>
57
</head>
68
<body>
7-
<div id="root">
8-
</div>
9-
<script src="/static/bundle.js"></script>
9+
<div id="root"></div>
10+
<!--
11+
This HTML file is a template.
12+
If you open it directly in the browser, you will see an empty page.
13+
14+
You can add webfonts, meta tags, or analytics to this file.
15+
The build step will place the bundled scripts into the <body> tag.
16+
17+
To begin the development, run `npm start` in this folder.
18+
To create a production bundle, use `npm run build`.
19+
-->
1020
</body>
1121
</html>

Diff for: examples/async/index.js

-15
This file was deleted.

Diff for: examples/async/package.json

+18-45
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,24 @@
11
{
2-
"name": "redux-async-example",
3-
"version": "0.0.0",
4-
"description": "Redux async example",
5-
"scripts": {
6-
"start": "node server.js"
7-
},
8-
"repository": {
9-
"type": "git",
10-
"url": "https://github.com/reactjs/redux.git"
11-
},
12-
"keywords": [
13-
"react",
14-
"reactjs",
15-
"hot",
16-
"reload",
17-
"hmr",
18-
"live",
19-
"edit",
20-
"webpack",
21-
"flux"
22-
],
23-
"license": "MIT",
24-
"bugs": {
25-
"url": "https://github.com/reactjs/redux/issues"
2+
"name": "async",
3+
"version": "0.0.1",
4+
"private": true,
5+
"devDependencies": {
6+
"react-scripts": "^0.4.0",
7+
"redux-logger": "^2.6.1"
268
},
27-
"homepage": "http://redux.js.org",
289
"dependencies": {
29-
"babel-polyfill": "^6.3.14",
30-
"isomorphic-fetch": "^2.1.1",
31-
"react": "^0.14.7",
32-
"react-dom": "^0.14.7",
33-
"react-redux": "^4.2.1",
34-
"redux": "^3.2.1",
35-
"redux-logger": "^2.4.0",
36-
"redux-thunk": "^1.0.3"
10+
"react": "^15.3.0",
11+
"react-dom": "^15.3.0",
12+
"react-redux": "^4.4.5",
13+
"redux": "^3.5.2",
14+
"redux-thunk": "^2.1.0"
3715
},
38-
"devDependencies": {
39-
"babel-core": "^6.3.15",
40-
"babel-loader": "^6.2.0",
41-
"babel-preset-es2015": "^6.3.13",
42-
"babel-preset-react": "^6.3.13",
43-
"babel-preset-react-hmre": "^1.1.1",
44-
"expect": "^1.6.0",
45-
"express": "^4.13.3",
46-
"node-libs-browser": "^0.5.2",
47-
"webpack": "^1.9.11",
48-
"webpack-dev-middleware": "^1.2.0",
49-
"webpack-hot-middleware": "^2.9.1"
16+
"scripts": {
17+
"start": "react-scripts start",
18+
"build": "react-scripts build",
19+
"eject": "react-scripts eject"
20+
},
21+
"eslintConfig": {
22+
"extends": "./node_modules/react-scripts/config/eslint.js"
5023
}
5124
}

Diff for: examples/async/server.js

-23
This file was deleted.

Diff for: examples/async/actions/index.js renamed to examples/async/src/actions/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import fetch from 'isomorphic-fetch'
2-
31
export const REQUEST_POSTS = 'REQUEST_POSTS'
42
export const RECEIVE_POSTS = 'RECEIVE_POSTS'
53
export const SELECT_REDDIT = 'SELECT_REDDIT'
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: examples/async/src/index.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react'
2+
import { render } from 'react-dom'
3+
import { createStore, applyMiddleware } from 'redux'
4+
import { Provider } from 'react-redux'
5+
import thunk from 'redux-thunk'
6+
import createLogger from 'redux-logger'
7+
import reducer from './reducers'
8+
import App from './containers/App'
9+
10+
const middleware = [ thunk ]
11+
if (process.env.NODE_ENV !== 'production') {
12+
middleware.push(createLogger())
13+
}
14+
15+
const store = createStore(
16+
reducer,
17+
applyMiddleware(...middleware)
18+
)
19+
20+
render(
21+
<Provider store={store}>
22+
<App />
23+
</Provider>,
24+
document.getElementById('root')
25+
)

Diff for: examples/async/reducers/index.js renamed to examples/async/src/reducers/index.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,24 @@ function posts(state = {
2020
}, action) {
2121
switch (action.type) {
2222
case INVALIDATE_REDDIT:
23-
return Object.assign({}, state, {
23+
return {
24+
...state,
2425
didInvalidate: true
25-
})
26+
}
2627
case REQUEST_POSTS:
27-
return Object.assign({}, state, {
28+
return {
29+
...state,
2830
isFetching: true,
2931
didInvalidate: false
30-
})
32+
}
3133
case RECEIVE_POSTS:
32-
return Object.assign({}, state, {
34+
return {
35+
...state,
3336
isFetching: false,
3437
didInvalidate: false,
3538
items: action.posts,
3639
lastUpdated: action.receivedAt
37-
})
40+
}
3841
default:
3942
return state
4043
}
@@ -45,9 +48,10 @@ function postsByReddit(state = { }, action) {
4548
case INVALIDATE_REDDIT:
4649
case RECEIVE_POSTS:
4750
case REQUEST_POSTS:
48-
return Object.assign({}, state, {
51+
return {
52+
...state,
4953
[action.reddit]: posts(state[action.reddit], action)
50-
})
54+
}
5155
default:
5256
return state
5357
}

Diff for: examples/async/store/configureStore.js

-22
This file was deleted.

Diff for: examples/async/webpack.config.js

-29
This file was deleted.

Diff for: examples/counter/.babelrc

-8
This file was deleted.

Diff for: examples/counter/.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# dependencies
4+
node_modules
5+
6+
# production
7+
build
8+
9+
# misc
10+
.DS_Store
11+
npm-debug.log

Diff for: examples/counter/README.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Redux Counter Example
2+
3+
This project template was built with [Create React App](https://github.com/facebookincubator/create-react-app).
4+
5+
## Available Scripts
6+
7+
In the project directory, you can run:
8+
9+
### `npm start`
10+
11+
Runs the app in the development mode.<br>
12+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
13+
14+
The page will reload if you make edits.<br>
15+
You will also see any lint errors in the console.
16+
17+
### `npm run build`
18+
19+
Builds the app for production to the `build` folder.<br>
20+
It correctly bundles React in production mode and optimizes the build for the best performance.
21+
22+
The build is minified and the filenames include the hashes.<br>
23+
Your app is ready to be deployed!
24+
25+
### `npm run eject`
26+
27+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
28+
29+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
30+
31+
Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
32+
33+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

0 commit comments

Comments
 (0)