Commit 0a19ff71e90207bdc5e6b22d5470c11617f9f7b0
boil the plates
Michael Williams committed on 11/28/2015, 8:43:07 AMParent: a911726b99b0e4c5da2f7dd6d4905059b64b9500
Files changed
app/client.js | changed |
app/package.json | changed |
app/server.js | changed |
app/services/static.js | changed |
app/containers/app.js | added |
app/containers/dev-tools.js | added |
app/containers/root.js | added |
app/containers/todo-list.js | added |
app/routes.js | added |
app/state.js | added |
app/store.js | added |
client.js | changed |
package.json | changed |
server.js | changed |
app/client.js | ||
---|---|---|
@@ -1,26 +1,23 @@ | ||
1 | 1 | const React = require('react') |
2 | 2 | const { render } = require('react-dom') |
3 | 3 | const { createStore, applyMiddleware } = require('redux') |
4 | +import { reduxReactRouter, routerStateReducer, ReduxRouter } from 'redux-router'; | |
4 | 5 | const { Provider } = require('react-redux') |
5 | -const logger = require('redux-logger') | |
6 | 6 | const thunk = require('redux-thunk') |
7 | 7 | |
8 | -const reducer = require('./reducers') | |
9 | -const { getAllTodos } = require('./actions') | |
10 | -const App = require('./containers/App') | |
8 | +const createInitialState = require('app/state') | |
9 | +const configureStore = require('app/store') | |
10 | +const { getAllTodos } = require('app/actions') | |
11 | +const Root = require('app/containers/root') | |
11 | 12 | |
12 | -const middleware = process.env.NODE_ENV === 'production' ? | |
13 | - [ thunk ] : | |
14 | - [ thunk, logger() ] | |
13 | +const store = configureStore( | |
14 | + createInitialState() | |
15 | +) | |
15 | 16 | |
16 | -const createStoreWithMiddleware = applyMiddleware(...middleware)(createStore) | |
17 | -const store = createStoreWithMiddleware(reducer) | |
17 | +//store.dispatch(getAllTodos()) | |
18 | 18 | |
19 | -store.dispatch(getAllTodos()) | |
19 | +const main = document.createElement('main') | |
20 | 20 | |
21 | -render( | |
22 | - <Provider store={store}> | |
23 | - <App /> | |
24 | - </Provider>, | |
25 | - document.getElementById('root') | |
26 | -) | |
21 | +document.body.appendChild(main) | |
22 | + | |
23 | +render(<Root />, main) |
app/package.json | ||
---|---|---|
@@ -1,6 +1,15 @@ | ||
1 | 1 | { |
2 | 2 | "browser": { |
3 | 3 | "./api.js": "./clients/index.js", |
4 | 4 | "./config.js": "./config-browser.js" |
5 | + }, | |
6 | + "browserify": { | |
7 | + "transform": [ | |
8 | + "babelify", | |
9 | + "envify", | |
10 | + ["evalify", { "files": [ "config-browser.js" ] } ], | |
11 | + "bulkify", | |
12 | + "sheetify/transform" | |
13 | + ] | |
5 | 14 | } |
6 | 15 | } |
app/server.js | ||
---|---|---|
@@ -1,11 +1,29 @@ | ||
1 | 1 | const feathers = require('feathers') |
2 | -const { mapObj, reduce } = require('ramda') | |
2 | +const { mapObjIndexed, reduce, toPairs } = require('ramda') | |
3 | 3 | |
4 | -const createServices = require('./services') | |
4 | +const serviceCreators = require('./services') | |
5 | 5 | |
6 | -function start (config) { | |
7 | - const services = mapObj( | |
8 | - (serviceCreator, name) => serveCreator(config[name]), | |
6 | +module.exports = createServer | |
7 | + | |
8 | +const useAll = function (app, services) { | |
9 | + return reduce((app, [name, service]) => { | |
10 | + return app.use(`/${name}`, service) | |
11 | + }, app, toPairs(services)) | |
12 | +} | |
13 | + | |
14 | +function createServer (config) { | |
15 | + | |
16 | + const services = mapObjIndexed( | |
17 | + (serviceCreator, name) => { | |
18 | + return serviceCreator(config.services[name]) | |
19 | + }, | |
9 | 20 | serviceCreators |
10 | 21 | ) |
22 | + | |
23 | + const server = feathers() | |
24 | + | |
25 | + useAll(server, services) | |
26 | + | |
27 | + return server | |
11 | 28 | } |
29 | + |
app/services/static.js | ||
---|---|---|
@@ -1,5 +1,6 @@ | ||
1 | 1 | const serveStatic = require('serve-static') |
2 | +const { join } = require('path') | |
2 | 3 | |
3 | 4 | module.exports = createStaticService |
4 | 5 | |
5 | 6 | function createStaticService (config) { |
app/containers/app.js | ||
---|---|---|
@@ -1,0 +1,18 @@ | ||
1 | +const React = require('react') | |
2 | +const { connect } = require('react-redux') | |
3 | + | |
4 | +class App extends React.Component { | |
5 | + render () { | |
6 | + const { children } = this.props | |
7 | + | |
8 | + return <div> | |
9 | + <span>hello world!</span> | |
10 | + { children } | |
11 | + </div> | |
12 | + } | |
13 | +} | |
14 | + | |
15 | +module.exports = connect( | |
16 | + App, | |
17 | + (state) => { return {} } | |
18 | +) |
app/containers/dev-tools.js | ||
---|---|---|
@@ -1,0 +1,14 @@ | ||
1 | +const React = require('react') | |
2 | +const { createDevTools } = require('redux-devtools') | |
3 | +const LogMonitor = require('redux-devtools-log-monitor') | |
4 | +const DockMonitor = require('redux-devtools-dock-monitor') | |
5 | + | |
6 | +const DevTools = createDevTools( | |
7 | + <DockMonitor toggleVisibilityKey='H' | |
8 | + changePositionKey='Q'> | |
9 | + <LogMonitor /> | |
10 | + </DockMonitor> | |
11 | +) | |
12 | + | |
13 | +module.exports = DevTools | |
14 | + |
app/containers/root.js | ||
---|---|---|
@@ -1,0 +1,29 @@ | ||
1 | +const React = require('react') | |
2 | +const { Provider } = require('react-redux') | |
3 | +const { ReduxRouter } = require('redux-router') | |
4 | + | |
5 | +const routes = require('app/routes') | |
6 | + | |
7 | +if (process.env.NODE_ENV === 'development') { | |
8 | + const DevTools = require('app/containers/dev-tools') | |
9 | +} | |
10 | + | |
11 | +class Root extends React.Component { | |
12 | + render() { | |
13 | + const { store } = this.props; | |
14 | + | |
15 | + return ( | |
16 | + <Provider store={store}> | |
17 | + <div> | |
18 | + <ReduxRouter> | |
19 | + { routes } | |
20 | + </ReduxRouter> | |
21 | + (process.env.NODE_ENV === 'development') ? | |
22 | + <DevTools /> : null | |
23 | + </div> | |
24 | + </Provider> | |
25 | + ) | |
26 | + } | |
27 | +} | |
28 | + | |
29 | +module.exports = Root |
app/containers/todo-list.js | ||
---|---|---|
@@ -1,0 +1,15 @@ | ||
1 | +const React = require('react') | |
2 | +const { connect } = require('react-redux') | |
3 | + | |
4 | +class TodoList extends React.Component { | |
5 | + render () { | |
6 | + return <div> | |
7 | + todo list! | |
8 | + </div> | |
9 | + } | |
10 | +} | |
11 | + | |
12 | +module.exports = connect( | |
13 | + TodoList, | |
14 | + (state) => { return {} } | |
15 | +) |
app/routes.js | ||
---|---|---|
@@ -1,0 +1,12 @@ | ||
1 | +const { Route } = require('react-router') | |
2 | + | |
3 | +const App = require('app/containers/app') | |
4 | +const TodoList = require('app/containers/todo-list') | |
5 | + | |
6 | +const routes = ( | |
7 | + <Route path='/' component={App}> | |
8 | + <Route path='todos' component={TodoList} /> | |
9 | + </Route> | |
10 | +) | |
11 | + | |
12 | +module.exports = routes |
app/state.js | ||
---|---|---|
@@ -1,0 +1,9 @@ | ||
1 | +module.exports = createInitialState | |
2 | + | |
3 | +function createInitialState () { | |
4 | + const initialState = { | |
5 | + todos: {} | |
6 | + } | |
7 | + | |
8 | + return initialState | |
9 | +} |
app/store.js | ||
---|---|---|
@@ -1,0 +1,59 @@ | ||
1 | +const { createStore, compose, applyMiddleware } = require('redux') | |
2 | +const thunk = require('redux-thunk') | |
3 | +const logger = require('redux-logger') | |
4 | +const { reduxReactRouter, routerStateReducer, ReduxRouter } = require('redux-router') | |
5 | +const { createHistory } = require('history') | |
6 | + | |
7 | +const rootReducer = require('app/reducers') | |
8 | +const routes = require('routes') | |
9 | + | |
10 | +let storesEnhancers = [] | |
11 | +let middleware = [] | |
12 | + | |
13 | +middleware.push(thunk) | |
14 | + | |
15 | +if (process.env.NODE_ENV === 'development') { | |
16 | + const { persistState } = require('redux-devtools') | |
17 | + | |
18 | + middleware.push(logger()) | |
19 | +} | |
20 | + | |
21 | +storesEnhancers.push( | |
22 | + applyMiddleware(middleware) | |
23 | +) | |
24 | + | |
25 | +if (process.env.NODE_ENV === 'development') { | |
26 | + storesEnhancers.push(DevTools.instrument()) | |
27 | + storesEnhancers.push(persistState( | |
28 | + window.location.href.match( | |
29 | + /[?&]debug_session=([^&]+)\b/ | |
30 | + ) | |
31 | + )) | |
32 | +} | |
33 | + | |
34 | +storesEnhancers.push( | |
35 | + reduxReactRouter({ | |
36 | + routes, createHistory | |
37 | + }) | |
38 | +) | |
39 | + | |
40 | +const finalCreateStore = compose( | |
41 | + ...storesEnhancers | |
42 | +)(createStore) | |
43 | + | |
44 | +function configureStore(initialState) { | |
45 | + const store = finalCreateStore(rootReducer, initialState) | |
46 | + | |
47 | + if (process.env.NODE_ENV === 'development') { | |
48 | + if (module.hot) { | |
49 | + module.hot.accept('app/reducers', () => | |
50 | + store.replaceReducer(require('app/reducers')) | |
51 | + ) | |
52 | + } | |
53 | + } | |
54 | + | |
55 | + return store | |
56 | +} | |
57 | + | |
58 | +module.exports = configureStore | |
59 | + |
package.json | ||
---|---|---|
@@ -9,21 +9,15 @@ | ||
9 | 9 | "format": "snazzy --format", |
10 | 10 | "test": "(npm run spec & npm run feature)", |
11 | 11 | "spec": "node spec", |
12 | 12 | "feature": "node feature", |
13 | - "dev:client": "budo client --dir assets --serve bundle.js --live -- -d", | |
13 | + "dev:client": "watchify client -o assets/bundle.js -dv -p browserify-hmr", | |
14 | 14 | "dev:server": "nodemon server", |
15 | 15 | "prod:client": "browserify client -o assets/bundle.js -g uglifyify", |
16 | 16 | "prod:server": "node server", |
17 | - "dev": "npm-run-all -p dev:*", | |
18 | - "prod": "npm-run-all -s prod:*" | |
17 | + "dev": "NODE_ENV=development npm-run-all -p dev:*", | |
18 | + "prod": "NODE_ENV=production npm-run-all -s prod:*" | |
19 | 19 | }, |
20 | - "browserify": { | |
21 | - "transform": [ | |
22 | - "babelify", | |
23 | - "sheetify/transform" | |
24 | - ] | |
25 | - }, | |
26 | 20 | "repository": { |
27 | 21 | "type": "git", |
28 | 22 | "url": "git+https://github.com/ahdinosaur/production-todomvc.git" |
29 | 23 | }, |
@@ -50,27 +44,43 @@ | ||
50 | 44 | "node": "^4.0.0", |
51 | 45 | "npm": "^3.0.0" |
52 | 46 | }, |
53 | 47 | "devDependencies": { |
48 | + "browserify-hmr": "^0.3.1", | |
54 | 49 | "budo": "^6.1.0", |
55 | 50 | "cuke-tap": "^1.0.2", |
56 | 51 | "jsdom": "^7.1.0", |
57 | 52 | "nodemon": "^1.8.1", |
58 | - "tape": "^4.2.2" | |
53 | + "redux-devtools": "^3.0.0-beta-3", | |
54 | + "redux-devtools-dock-monitor": "^1.0.0-beta-3", | |
55 | + "redux-devtools-log-monitor": "^1.0.0-beta-3", | |
56 | + "redux-logger": "^2.0.4", | |
57 | + "tape": "^4.2.2", | |
58 | + "watchify": "^3.6.1" | |
59 | 59 | }, |
60 | 60 | "dependencies": { |
61 | 61 | "babel-core": "^6.2.1", |
62 | 62 | "babel-plugin-transform-object-rest-spread": "^6.1.18", |
63 | 63 | "babel-preset-es2015": "^6.1.18", |
64 | 64 | "babel-preset-react": "^6.1.18", |
65 | 65 | "babelify": "^7.2.0", |
66 | + "browserify": "^12.0.1", | |
66 | 67 | "bulk-require": "^0.2.1", |
67 | 68 | "bulkify": "^1.1.1", |
69 | + "envify": "^3.4.0", | |
68 | 70 | "evalify": "^1.0.1", |
69 | 71 | "feathers": "^1.2.0", |
72 | + "history": "^1.13.1", | |
70 | 73 | "lnfs-cli": "^1.0.1", |
71 | 74 | "npm-run-all": "^1.3.2", |
72 | 75 | "ramda": "^0.18.0", |
76 | + "react": "^0.14.3", | |
77 | + "react-dom": "^0.14.3", | |
78 | + "react-redux": "^4.0.0", | |
79 | + "react-router": "^1.0.0", | |
80 | + "redux": "^3.0.4", | |
81 | + "redux-router": "^1.0.0-beta4", | |
82 | + "redux-thunk": "^1.0.0", | |
73 | 83 | "sheetify": "^3.1.0", |
74 | 84 | "uglifyify": "^3.0.1" |
75 | 85 | } |
76 | 86 | } |
Built with git-ssb-web