Commit 99bc16e5212f7086422943407911f7c31443ab4c
fashion-driven development
use es2015 modules (import / export) instead of es5 modules (require, module.exports) unless where necessary (bulkify only recognizes es5 modules) - %s/^const \(.*\) = require('\(.*\)')$/import \1 from '\2'/i - %s/module.exports = /export defaultMichael Williams committed on 1/3/2016, 6:53:28 AM
Parent: 8d668726e7d11fcdfc803f3c47ed305680c7194f
Files changed
api.js | changed |
app/api.js | changed |
app/config.js | changed |
app/dev/root.js | changed |
app/dev/tools.js | changed |
app/four-oh-four/container.js | changed |
app/four-oh-four/routes.js | changed |
app/landing/component.js | changed |
app/landing/container.js | changed |
app/landing/routes.js | changed |
app/layout/container.js | changed |
app/reducer.js | changed |
app/render-browser.js | changed |
app/render.js | changed |
app/routes.js | changed |
app/services/index.js | changed |
app/stack/index.js | changed |
app/static.js | changed |
app/store.js | changed |
app/todos/container.js | changed |
app/todos/reducer.js | changed |
app/todos/routes.js | changed |
app/util/fetch-all-data.js | changed |
app/util/fetch-element.js | changed |
render.js | changed |
static.js | changed |
api.js | ||
---|---|---|
@@ -1,8 +1,8 @@ | ||
1 | 1 | require('babel-core/register') |
2 | 2 | |
3 | -const config = require('app/config') | |
4 | -const createApi = require('app/api') | |
3 | +const config = require('app/config').default | |
4 | +const createApi = require('app/api').default | |
5 | 5 | const Url = require('url') |
6 | 6 | |
7 | 7 | const server = createApi(config) |
8 | 8 |
app/api.js | ||
---|---|---|
@@ -1,13 +1,11 @@ | ||
1 | -const feathers = require('feathers') | |
2 | -const { mapObjIndexed, reduce, toPairs } = require('ramda') | |
1 | +import feathers from 'feathers' | |
2 | +import { mapObjIndexed, reduce, toPairs } from 'ramda' | |
3 | 3 | |
4 | -const services = require('app/services') | |
5 | -const config = require('app/config') | |
4 | +import services from 'app/services' | |
5 | +import config from 'app/config' | |
6 | 6 | |
7 | -module.exports = createServer | |
8 | - | |
9 | -function createServer (config) { | |
7 | +export default function createServer (config) { | |
10 | 8 | const app = feathers() |
11 | 9 | |
12 | 10 | useAll(app, services) |
13 | 11 |
app/config.js | ||
---|---|---|
@@ -1,1 +1,3 @@ | ||
1 | -module.exports = require('simple-rc')() | |
1 | +import getConfig from 'simple-rc' | |
2 | + | |
3 | +export default getConfig() |
app/dev/root.js | ||
---|---|---|
@@ -1,15 +1,15 @@ | ||
1 | -const React = require('react') | |
2 | -const { Provider } = require('react-redux') | |
3 | -const { ReduxRouter } = require('redux-router') | |
1 | +import React from 'react' | |
2 | +import { Provider } from 'react-redux' | |
3 | +import { ReduxRouter } from 'redux-router' | |
4 | 4 | |
5 | -const routes = require('app/routes') | |
5 | +import routes from 'app/routes' | |
6 | 6 | |
7 | 7 | if (process.env.NODE_ENV === 'development') { |
8 | 8 | var DevTools = require('app/components/dev-tools') |
9 | 9 | } |
10 | 10 | |
11 | -class Root extends React.Component { | |
11 | +export default class Root extends React.Component { | |
12 | 12 | render() { |
13 | 13 | const { store } = this.props; |
14 | 14 | |
15 | 15 | return ( |
@@ -26,6 +26,4 @@ | ||
26 | 26 | </Provider> |
27 | 27 | ) |
28 | 28 | } |
29 | 29 | } |
30 | - | |
31 | -module.exports = Root |
app/dev/tools.js | ||
---|---|---|
@@ -1,13 +1,11 @@ | ||
1 | -const React = require('react') | |
2 | -const { createDevTools } = require('redux-devtools') | |
3 | -const LogMonitor = require('redux-devtools-log-monitor').default | |
4 | -const DockMonitor = require('redux-devtools-dock-monitor').default | |
1 | +import React from 'react' | |
2 | +import { createDevTools } from 'redux-devtools' | |
3 | +import LogMonitor from 'redux-devtools-log-monitor' | |
4 | +import DockMonitor from 'redux-devtools-dock-monitor' | |
5 | 5 | |
6 | -const DevTools = createDevTools( | |
6 | +export default createDevTools( | |
7 | 7 | <DockMonitor toggleVisibilityKey='H' |
8 | 8 | changePositionKey='Q'> |
9 | 9 | <LogMonitor /> |
10 | 10 | </DockMonitor> |
11 | 11 | ) |
12 | - | |
13 | -module.exports = DevTools |
app/four-oh-four/container.js | ||
---|---|---|
@@ -1,6 +1,6 @@ | ||
1 | -const React = require('react') | |
2 | -const { connect } = require('react-redux') | |
1 | +import React from 'react' | |
2 | +import { connect } from 'react-redux' | |
3 | 3 | |
4 | 4 | class FourOhFourContainer extends React.Component { |
5 | 5 | render () { |
6 | 6 | return <div> |
@@ -8,7 +8,7 @@ | ||
8 | 8 | </div> |
9 | 9 | } |
10 | 10 | } |
11 | 11 | |
12 | -module.exports = connect( | |
12 | +export default connect( | |
13 | 13 | (state) => ({}) |
14 | 14 | )(FourOhFourContainer) |
app/four-oh-four/routes.js | ||
---|---|---|
@@ -1,6 +1,6 @@ | ||
1 | -const React = require('react') | |
2 | -const { Route } = require('react-router') | |
1 | +import React from 'react' | |
2 | +import { Route } from 'react-router' | |
3 | 3 | |
4 | -const FourOhFourContainer = require('./container') | |
4 | +import FourOhFourContainer from './container' | |
5 | 5 | |
6 | -module.exports = <Route path="*" component={FourOhFourContainer} /> | |
6 | +export default <Route path="*" component={FourOhFourContainer} /> |
app/landing/component.js | ||
---|---|---|
@@ -1,13 +1,11 @@ | ||
1 | -const React = require('react') | |
1 | +import React from 'react' | |
2 | 2 | |
3 | -const style = require('./style.css') | |
3 | +import style from './style.css' | |
4 | 4 | |
5 | -class Landing extends React.Component { | |
5 | +export default class Landing extends React.Component { | |
6 | 6 | render () { |
7 | 7 | return <div className={style.container}> |
8 | 8 | landing! |
9 | 9 | </div> |
10 | 10 | } |
11 | 11 | } |
12 | - | |
13 | -module.exports = Landing |
app/landing/container.js | ||
---|---|---|
@@ -1,14 +1,14 @@ | ||
1 | -const React = require('react') | |
2 | -const { connect } = require('react-redux') | |
1 | +import React from 'react' | |
2 | +import { connect } from 'react-redux' | |
3 | 3 | |
4 | -const Landing = require('./component') | |
4 | +import Landing from './component' | |
5 | 5 | |
6 | 6 | class LandingContainer extends React.Component { |
7 | 7 | render () { |
8 | 8 | return <Landing /> |
9 | 9 | } |
10 | 10 | } |
11 | 11 | |
12 | -module.exports = connect( | |
12 | +export default connect( | |
13 | 13 | (state) => ({}) |
14 | 14 | )(LandingContainer) |
app/landing/routes.js | ||
---|---|---|
@@ -1,6 +1,6 @@ | ||
1 | -const React = require('react') | |
2 | -const { IndexRoute } = require('react-router') | |
1 | +import React from 'react' | |
2 | +import { IndexRoute } from 'react-router' | |
3 | 3 | |
4 | -const LandingContainer = require('./container') | |
4 | +import LandingContainer from './container' | |
5 | 5 | |
6 | -module.exports = <IndexRoute component={LandingContainer} /> | |
6 | +export default <IndexRoute component={LandingContainer} /> |
app/layout/container.js | ||
---|---|---|
@@ -1,6 +1,6 @@ | ||
1 | -const React = require('react') | |
2 | -const { connect } = require('react-redux') | |
1 | +import React from 'react' | |
2 | +import { connect } from 'react-redux' | |
3 | 3 | |
4 | 4 | class LayoutContainer extends React.Component { |
5 | 5 | render () { |
6 | 6 | const { children } = this.props |
@@ -11,7 +11,7 @@ | ||
11 | 11 | </div> |
12 | 12 | } |
13 | 13 | } |
14 | 14 | |
15 | -module.exports = connect( | |
15 | +export default connect( | |
16 | 16 | (state) => ({}) |
17 | 17 | )(LayoutContainer) |
app/reducer.js | ||
---|---|---|
@@ -1,16 +1,18 @@ | ||
1 | 1 | const bulk = require('bulk-require') |
2 | -const { combineReducers } = require('redux') | |
3 | -const { routeReducer } = require('redux-simple-router') | |
4 | -const { map } = require('ramda') | |
2 | +import { combineReducers } from 'redux' | |
3 | +import { routeReducer } from 'redux-simple-router' | |
4 | +import { map } from 'ramda' | |
5 | 5 | |
6 | -module.exports = combineReducers({ | |
6 | +export default combineReducers({ | |
7 | 7 | ...map( |
8 | - (module) => module.reducer, | |
8 | + (module) => module.reducer.default, | |
9 | 9 | bulk(__dirname, '*/reducer.js') |
10 | 10 | ), |
11 | 11 | ...map( |
12 | - (module) => combineReducers(module.reducers), | |
12 | + (module) => combineReducers( | |
13 | + module.reducers.map(m => m.default) | |
14 | + ), | |
13 | 15 | bulk(__dirname, '*/reducers/*.js') |
14 | 16 | ), |
15 | 17 | routing: routeReducer |
16 | 18 | }) |
app/render-browser.js | ||
---|---|---|
@@ -1,16 +1,17 @@ | ||
1 | -const React = require('react') | |
2 | -const { render } = require('react-dom') | |
3 | -const { Provider } = require('react-redux') | |
4 | -const { Router } = require('react-router') | |
5 | -const { createHistory } = require('history') | |
6 | -const { syncReduxAndRouter } = require('redux-simple-router') | |
1 | +import React from 'react' | |
2 | +import { render } from 'react-dom' | |
3 | +import { Provider } from 'react-redux' | |
4 | +import { Router } from 'react-router' | |
5 | +import { createHistory } from 'history' | |
6 | +import { syncReduxAndRouter } from 'redux-simple-router' | |
7 | 7 | |
8 | -const routes = require('app/routes') | |
9 | -const createStore = require('app/store') | |
10 | -const fetchElement = require('app/util/fetch-element') | |
8 | +import routes from 'app/routes' | |
9 | +import createStore from 'app/store' | |
10 | +import fetchElement from 'app/util/fetch-element' | |
11 | 11 | |
12 | 12 | if (process.env.NODE_ENV === 'development') { |
13 | + var DevTools = require('app/dev/tools').default | |
13 | 14 | } |
14 | 15 | |
15 | 16 | const store = createStore(window.__data) |
16 | 17 | const history = createHistory() |
@@ -30,10 +31,8 @@ | ||
30 | 31 | document.querySelector('main') |
31 | 32 | ) |
32 | 33 | |
33 | 34 | if (process.env.NODE_ENV === 'development') { |
34 | - const DevTools = require('app/dev/tools') | |
35 | - | |
36 | 35 | render( |
37 | 36 | <Provider store={store} key="provider"> |
38 | 37 | <div> |
39 | 38 | { main } |
app/render.js | ||
---|---|---|
@@ -1,24 +1,22 @@ | ||
1 | 1 | // https://github.com/jlongster/react-redux-universal-hot-example/blob/master/src/server.js |
2 | 2 | |
3 | -const http =require('http') | |
4 | -const Url = require('url') | |
5 | -const React = require('react') | |
6 | -const { renderToString } = require('react-dom/server') | |
7 | -const { Provider } = require('react-redux') | |
8 | -const { createHistory } = require('history') | |
9 | -const { Router, RoutingContext, match } = require('react-router') | |
10 | -const sendHtml = require('send-data/html') | |
11 | -const sendError = require('send-data/error') | |
12 | -const redirect = require('predirect') | |
3 | +import http from 'http' | |
4 | +import Url from 'url' | |
5 | +import React from 'react' | |
6 | +import { renderToString } from 'react-dom/server' | |
7 | +import { Provider } from 'react-redux' | |
8 | +import { createHistory } from 'history' | |
9 | +import { Router, RoutingContext, match } from 'react-router' | |
10 | +import sendHtml from 'send-data/html' | |
11 | +import sendError from 'send-data/error' | |
12 | +import redirect from 'predirect' | |
13 | 13 | |
14 | -const createStore = require('app/store') | |
15 | -const routes = require('app/routes') | |
16 | -const fetchAllData = require('app/util/fetch-all-data') | |
14 | +import createStore from 'app/store' | |
15 | +import routes from 'app/routes' | |
16 | +import fetchAllData from 'app/util/fetch-all-data' | |
17 | 17 | |
18 | -module.exports = createRender | |
19 | - | |
20 | -function createRender (config) { | |
18 | +export default function createRender (config) { | |
21 | 19 | const staticUrl = Url.format(config.static.url) |
22 | 20 | |
23 | 21 | return http.createServer(render) |
24 | 22 |
app/routes.js | ||
---|---|---|
@@ -1,24 +1,22 @@ | ||
1 | -const React = require('react') | |
2 | -const { Route, IndexRoute } = require('react-router') | |
3 | 1 | const bulk = require('bulk-require') |
4 | -const { mapObjIndexed, values } = require('ramda') | |
2 | +import React from 'react' | |
3 | +import { Route, IndexRoute } from 'react-router' | |
4 | +import { mapObjIndexed, values } from 'ramda' | |
5 | 5 | |
6 | -const LayoutContainer = require('app/layout/container') | |
7 | -const FourOhFourRoutes = require('app/four-oh-four/routes') | |
6 | +import LayoutContainer from 'app/layout/container' | |
7 | +import FourOhFourRoutes from 'app/four-oh-four/routes' | |
8 | 8 | |
9 | -const routes = ( | |
9 | +export default ( | |
10 | 10 | <Route path='/' component={LayoutContainer}> |
11 | 11 | { |
12 | 12 | values(mapObjIndexed( |
13 | 13 | (module, moduleName) => ({ |
14 | - ...module.routes, | |
14 | + ...module.routes.default, | |
15 | 15 | key: moduleName |
16 | 16 | }), |
17 | 17 | bulk(__dirname, '!(four-oh-four)/routes.js') |
18 | 18 | )) |
19 | 19 | } |
20 | 20 | { FourOhFourRoutes } |
21 | 21 | </Route> |
22 | 22 | ) |
23 | - | |
24 | -module.exports = routes |
app/services/index.js | ||
---|---|---|
@@ -1,10 +1,13 @@ | ||
1 | 1 | const bulk = require('bulk-require') |
2 | -const { map } = require('ramda') | |
2 | +import { map } from 'ramda' | |
3 | 3 | |
4 | -module.exports = { | |
5 | - ...bulk(__dirname, '*/service.js'), | |
4 | +export default { | |
6 | 5 | ...map( |
7 | - (module) => module.services, | |
6 | + (module) => m.service.default, | |
7 | + bulk(__dirname, '*/service.js') | |
8 | + ), | |
9 | + ...map( | |
10 | + (module) => module.services.map(m => m.default), | |
8 | 11 | bulk(__dirname, '*/services/*.js') |
9 | 12 | ) |
10 | 13 | } |
app/stack/index.js | ||
---|---|---|
@@ -1,16 +1,14 @@ | ||
1 | -const feathers = require('feathers') | |
2 | -const { mapObjIndexed, reduce, toPairs } = require('ramda') | |
1 | +import feathers from 'feathers' | |
2 | +import { mapObjIndexed, reduce, toPairs } from 'ramda' | |
3 | 3 | |
4 | 4 | const stackCreators = { |
5 | 5 | services: require('./services'), |
6 | 6 | static: require('./static'), |
7 | 7 | render: require('./render') |
8 | 8 | } |
9 | 9 | |
10 | -module.exports = createStack | |
11 | - | |
12 | -function createStack(config) { | |
10 | +export default function createStack(config) { | |
13 | 11 | const stacks = createStacks(config) |
14 | 12 | |
15 | 13 | const app = feathers() |
16 | 14 |
app/static.js | ||
---|---|---|
@@ -1,9 +1,7 @@ | ||
1 | -const http = require('http') | |
1 | +import http from 'http' | |
2 | 2 | |
3 | -module.exports = createStatic | |
4 | - | |
5 | -function createStatic (config) { | |
3 | +export default function createStatic (config) { | |
6 | 4 | const ecstatic = config.livereload ? |
7 | 5 | require('ecstatic-lr') : require('ecstatic') |
8 | 6 | |
9 | 7 | return http.createServer( |
app/store.js | ||
---|---|---|
@@ -1,10 +1,15 @@ | ||
1 | -const { createStore, compose, applyMiddleware } = require('redux') | |
2 | -const thunk = require('redux-thunk') | |
3 | -const { createHistory } = require('history') | |
1 | +import { createStore, compose, applyMiddleware } from 'redux' | |
2 | +import thunk from 'redux-thunk' | |
3 | +import { createHistory } from 'history' | |
4 | 4 | |
5 | -const reducer = require('app/reducer') | |
5 | +import reducer from 'app/reducer' | |
6 | 6 | |
7 | +if (process.env.NODE_ENV === 'development') { | |
8 | + var logger = require('redux-logger') | |
9 | + var DevTools = require('app/dev/tools').default | |
10 | +} | |
11 | + | |
7 | 12 | let storeEnhancers = [] |
8 | 13 | let middleware = [] |
9 | 14 | |
10 | 15 | middleware.push(thunk) |
@@ -13,14 +18,12 @@ | ||
13 | 18 | applyMiddleware(...middleware) |
14 | 19 | ) |
15 | 20 | |
16 | 21 | if (process.env.NODE_ENV === 'development') { |
17 | - let logger = require('redux-logger') | |
18 | 22 | storeEnhancers.push( |
19 | 23 | applyMiddleware(logger()) |
20 | 24 | ) |
21 | 25 | |
22 | - let DevTools = require('app/dev/tools') | |
23 | 26 | storeEnhancers.push(DevTools.instrument()) |
24 | 27 | |
25 | 28 | if (module.browser) { |
26 | 29 | let { persistState } = require('redux-devtools') |
@@ -35,16 +38,15 @@ | ||
35 | 38 | const createEnhancedStore = compose( |
36 | 39 | ...storeEnhancers |
37 | 40 | )(createStore) |
38 | 41 | |
39 | -function finalCreateStore(initialState) { | |
42 | +export default function finalCreateStore(initialState) { | |
43 | + const store = createEnhancedStore(reducer, initialState) | |
40 | 44 | |
41 | 45 | if (module.hot) { |
42 | 46 | module.hot.accept('app/reducer', () => { |
43 | 47 | store.replaceReducer(require('app/reducer')) |
44 | 48 | }) |
45 | 49 | } |
46 | 50 | |
47 | - return createEnhancedStore(reducer, initialState) | |
51 | + return store | |
48 | 52 | } |
49 | - | |
50 | -module.exports = finalCreateStore |
app/todos/container.js | ||
---|---|---|
@@ -1,6 +1,6 @@ | ||
1 | -const React = require('react') | |
2 | -const { connect } = require('react-redux') | |
1 | +import React from 'react' | |
2 | +import { connect } from 'react-redux' | |
3 | 3 | |
4 | 4 | class TodosContainer extends React.Component { |
5 | 5 | render () { |
6 | 6 | return <div> |
@@ -8,7 +8,7 @@ | ||
8 | 8 | </div> |
9 | 9 | } |
10 | 10 | } |
11 | 11 | |
12 | -module.exports = connect( | |
12 | +export default connect( | |
13 | 13 | (state) => ({}) |
14 | 14 | )(TodosContainer) |
app/todos/reducer.js | ||
---|---|---|
@@ -1,7 +1,5 @@ | ||
1 | -module.exports = todos | |
2 | - | |
3 | -function todos (state = {}, action) { | |
1 | +export default function todos (state = {}, action) { | |
4 | 2 | switch (action.type) { |
5 | 3 | case 'CREATE_TODO': |
6 | 4 | return { |
7 | 5 | ...state, |
app/todos/routes.js | ||
---|---|---|
@@ -1,6 +1,6 @@ | ||
1 | -const React = require('react') | |
2 | -const { Route } = require('react-router') | |
1 | +import React from 'react' | |
2 | +import { Route } from 'react-router' | |
3 | 3 | |
4 | -const TodosContainer = require('./container') | |
4 | +import TodosContainer from './container' | |
5 | 5 | |
6 | -module.exports = <Route path="todos" component={TodosContainer} /> | |
6 | +export default <Route path="todos" component={TodosContainer} /> |
app/util/fetch-all-data.js | ||
---|---|---|
@@ -1,11 +1,9 @@ | ||
1 | 1 | // https://github.com/jlongster/react-redux-universal-hot-example/blob/master/src/helpers/fetchAllData.js |
2 | 2 | |
3 | -const Promise = require('pinkie-promise') | |
3 | +import Promise from 'pinkie-promise' | |
4 | 4 | |
5 | -module.exports = fetchAllData | |
6 | - | |
7 | -function fetchAllData(components, getState, dispatch, location, params) { | |
5 | +export default function fetchAllData(components, getState, dispatch, location, params) { | |
8 | 6 | const fetchers = components |
9 | 7 | .filter((component) => !!component) // Weed out 'undefined' routes |
10 | 8 | .filter((component) => component.fetchData) // only look at ones with a static fetchData() |
11 | 9 | .map((component) => component.fetchData) // pull out fetch data methods |
app/util/fetch-element.js | ||
---|---|---|
@@ -1,9 +1,7 @@ | ||
1 | -const React = require('react') | |
1 | +import React from 'react' | |
2 | 2 | |
3 | -module.exports = fetchElement | |
4 | - | |
5 | -function fetchElement (Component, props) { | |
3 | +export default function fetchElement (Component, props) { | |
6 | 4 | if (Component.fetchData) { |
7 | 5 | Component.fetchData( |
8 | 6 | store.getState, store.dispatch, |
9 | 7 | props.location, props.params |
render.js | ||
---|---|---|
@@ -1,9 +1,9 @@ | ||
1 | 1 | require('babel-core/register') |
2 | 2 | require('css-modules-require-hook') |
3 | 3 | |
4 | -const config = require('app/config') | |
5 | -const createRender = require('app/render') | |
4 | +const config = require('app/config').default | |
5 | +const createRender = require('app/render').default | |
6 | 6 | const Url = require('url') |
7 | 7 | |
8 | 8 | const server = createRender(config) |
9 | 9 |
static.js | ||
---|---|---|
@@ -1,6 +1,8 @@ | ||
1 | -const config = require('app/config') | |
2 | -const createStatic = require('app/static') | |
1 | +require('babel-core/register') | |
2 | + | |
3 | +const config = require('app/config').default | |
4 | +const createStatic = require('app/static').default | |
3 | 5 | const Url = require('url') |
4 | 6 | |
5 | 7 | const server = createStatic(config) |
6 | 8 |
Built with git-ssb-web