Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Commit

Permalink
Rerun Prettier to match config
Browse files Browse the repository at this point in the history
  • Loading branch information
tptee committed Jan 30, 2018
1 parent 515ca12 commit 3509647
Show file tree
Hide file tree
Showing 42 changed files with 1,577 additions and 1,472 deletions.
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dist/
lib/
es/
flow-typed/
.nyc-output/
package-lock.json
67 changes: 32 additions & 35 deletions ADVANCED.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Advanced Docs

## Server Rendering

`redux-little-router` supports React server rendering with an Express or Hapi adapter.

Make sure to read http://redux.js.org/docs/recipes/ServerRendering.html to understand how the server/client Redux boilerplate works.
Expand Down Expand Up @@ -32,15 +33,15 @@ const routes = {
app.use('/*', (req, res) => {
// Create the Redux store, passing in the Express
// request to the routerForExpress factory.
//
//
// If you're using an Express sub-router,
// routerForExpress will infer the basename
// from req.baseUrl!
//
//
const { reducer, middleware, enhancer } = routerForExpress({
routes,
request: req
})
});

const store = createStore(
combineReducers({ router: reducer }),
Expand All @@ -50,7 +51,7 @@ app.use('/*', (req, res) => {

// ...then renderToString() your components as usual,
// passing your new store to your <Provider> component.
//
//
// Don't forget to attach your ESCAPED initialState to
// a script tag in your template that attaches to
// something like window.__INITIAL_STATE.
Expand Down Expand Up @@ -80,30 +81,30 @@ const routes = {
};

server.route({
method: 'GET',
path: '/{wild*}',
handler: (request, reply) => {
// Create the Redux store, passing in the Hapi
// request to the routerForHapi factory.

const { reducer, middleware, enhancer } = routerForHapi({
routes,
request
})

const store = createStore(
reducer,
{ what: 'ever' },
compose(enhancer, applyMiddleware(middleware))
);

// ...then renderToString() your components as usual,
// passing your new store to your <Provider> component.
//
// Don't forget to attach your ESCAPED initialState to
// a script tag in your template that attaches to
// something like window.__INITIAL_STATE.
}
method: 'GET',
path: '/{wild*}',
handler: (request, reply) => {
// Create the Redux store, passing in the Hapi
// request to the routerForHapi factory.

const { reducer, middleware, enhancer } = routerForHapi({
routes,
request
});

const store = createStore(
reducer,
{ what: 'ever' },
compose(enhancer, applyMiddleware(middleware))
);

// ...then renderToString() your components as usual,
// passing your new store to your <Provider> component.
//
// Don't forget to attach your ESCAPED initialState to
// a script tag in your template that attaches to
// something like window.__INITIAL_STATE.
}
});
```

Expand All @@ -123,11 +124,7 @@ const routes = {
}
};

const {
reducer,
enhancer,
middleware
} = routerForBrowser({ routes });
const { reducer, enhancer, middleware } = routerForBrowser({ routes });

const store = createStore(
combineReducers({ router: reducer }),
Expand All @@ -152,8 +149,8 @@ import { replaceRoutes } from 'redux-little-router';
const mergeRoutes = newRoutes => (dispatch, getState) => {
const currentRoutes = getState().routes;
return dispatch(replaceRoutes(merge(currentRoutes, newRoutes)));
}
};

// Later, maybe in a `connect()ed component`
loadSomeAsyncRoutes().then(routes => dispatch(mergeRoutes()))
loadSomeAsyncRoutes().then(routes => dispatch(mergeRoutes()));
```
6 changes: 1 addition & 5 deletions config/webpack/demo/webpack.config.demo.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ const babel = require('../partials/babel');
const cssModules = require('../partials/css-modules');
const sourceMaps = require('../partials/sourcemaps-inline');

const extendConfig = compose(
babel(),
cssModules(),
sourceMaps()
);
const extendConfig = compose(babel(), cssModules(), sourceMaps());

module.exports = extendConfig({
devServer: {
Expand Down
2 changes: 1 addition & 1 deletion config/webpack/demo/webpack.config.demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const extendConfig = compose(

module.exports = extendConfig({
cache: true,
context: path.resolve("demo/client"),
context: path.resolve('demo/client'),
entry: './app.js',
output: {
path: path.resolve('demo/dist'),
Expand Down
15 changes: 8 additions & 7 deletions config/webpack/partials/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

const loader = require('webpack-partial/loader').default;

module.exports = opts => loader({
test: /\.jsx?$/,
exclude: /node_modules/,
include: process.cwd(),
loader: require.resolve('babel-loader'),
query: opts
});
module.exports = opts =>
loader({
test: /\.jsx?$/,
exclude: /node_modules/,
include: process.cwd(),
loader: require.resolve('babel-loader'),
query: opts
});
34 changes: 21 additions & 13 deletions config/webpack/partials/css-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const ExtractTextPlugin = require('extract-text-webpack-plugin');
const loader = require('webpack-partial/loader').default;
const plugin = require('webpack-partial/plugin').default;

module.exports = function (opts) {
module.exports = function(opts) {
opts = _.defaults(opts, {
production: false,
cssOpts: {}
Expand All @@ -20,15 +20,18 @@ module.exports = function (opts) {
use: [
{
loader: require.resolve('css-loader'),
options: _.assign({
autoprefixer: false,
mergeRules: false, // disable or keyframes break
modules: true,
sourceMap: true,
importLoaders: 1,
localIdentName: '[local]___[hash:base64:5]',
context: 'src'
}, opts.cssOpts)
options: _.assign(
{
autoprefixer: false,
mergeRules: false, // disable or keyframes break
modules: true,
sourceMap: true,
importLoaders: 1,
localIdentName: '[local]___[hash:base64:5]',
context: 'src'
},
opts.cssOpts
)
},
{
loader: require.resolve('postcss-loader'),
Expand All @@ -45,9 +48,14 @@ module.exports = function (opts) {
plugin(
// Hashes in CSS file names make the dev server choke.
// Only enable hashes in production!
new ExtractTextPlugin(_.assign({
filename: `[name]${opts.production ? '.[hash]' : ''}.css`
}, opts.extractTextPlugin))
new ExtractTextPlugin(
_.assign(
{
filename: `[name]${opts.production ? '.[hash]' : ''}.css`
},
opts.extractTextPlugin
)
)
)
);
};
16 changes: 11 additions & 5 deletions config/webpack/partials/define.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ const _ = require('lodash');
const plugin = require('webpack-partial/plugin').default;
const DefinePlugin = require('webpack').DefinePlugin;

module.exports = function (opts) {
module.exports = function(opts) {
opts = _.defaults(opts, {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
'process.env.NODE_ENV': JSON.stringify(
process.env.NODE_ENV || 'development'
)
});

const define = _.reduce(opts, (accumulator, value, key) => {
return _.set(accumulator, key, JSON.stringify(value));
}, {});
const define = _.reduce(
opts,
(accumulator, value, key) => {
return _.set(accumulator, key, JSON.stringify(value));
},
{}
);

return plugin(new DefinePlugin(define));
};
21 changes: 12 additions & 9 deletions config/webpack/partials/optimize.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ const CompressionPlugin = require('compression-webpack-plugin');
const plugin = require('webpack-partial/plugin').default;
const optimize = require('webpack').optimize;

module.exports = () => flow(
plugin(new optimize.UglifyJsPlugin()),
plugin(new CompressionPlugin({
asset: '[path].gz[query]',
test: /\.js$|\.css$/,
algorithm: 'gzip',
threshold: 1500
}))
);
module.exports = () =>
flow(
plugin(new optimize.UglifyJsPlugin()),
plugin(
new CompressionPlugin({
asset: '[path].gz[query]',
test: /\.js$|\.css$/,
algorithm: 'gzip',
threshold: 1500
})
)
);
23 changes: 12 additions & 11 deletions config/webpack/partials/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
const { smart: mergeWebpackConfig } = require('webpack-merge');
const path = require('path');

module.exports = () => config => mergeWebpackConfig(config, {
resolve: {
// Alias `react` to copy in this repo's `node_modules`.
// Solves an issue where Webpack includes multiple versions of React when using
// npm link to install a package that also includes React as a dependency.
//
// http://www.justincarmony.com/blog/2015/04/02/webpack-react-multiple-versions-issues/
alias: {
'react': path.dirname(require.resolve("react/package.json"))
module.exports = () => config =>
mergeWebpackConfig(config, {
resolve: {
// Alias `react` to copy in this repo's `node_modules`.
// Solves an issue where Webpack includes multiple versions of React when using
// npm link to install a package that also includes React as a dependency.
//
// http://www.justincarmony.com/blog/2015/04/02/webpack-react-multiple-versions-issues/
alias: {
react: path.dirname(require.resolve('react/package.json'))
}
}
}
});
});
8 changes: 5 additions & 3 deletions config/webpack/partials/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const plugin = require('webpack-partial/plugin').default;
const StatsWriterPlugin = require('webpack-stats-plugin').StatsWriterPlugin;

module.exports = () =>
plugin(new StatsWriterPlugin({
filename: '../stats/stats.json'
}));
plugin(
new StatsWriterPlugin({
filename: '../stats/stats.json'
})
);
4 changes: 1 addition & 3 deletions config/webpack/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ const config = require('./webpack.config');
// **WARNING**: Mutates base configuration.
// We do this because lodash isn't available in `production` mode.
config.output.filename = config.output.filename.replace(/\.min\.js$/, '.js');
config.plugins = [
new webpack.SourceMapDevToolPlugin('[file].map')
];
config.plugins = [new webpack.SourceMapDevToolPlugin('[file].map')];

// Export mutated base.
module.exports = config;
21 changes: 10 additions & 11 deletions demo/client/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ const columnize = (array, columns) => {
);
};

const Gallery = ({ images, columns, ...rest }) =>
const Gallery = ({ images, columns, ...rest }) => (
<div className={styles.gallery} {...rest}>
{columnize(images, columns).map((column, index) =>
{columnize(images, columns).map((column, index) => (
<div key={index} className={styles.column}>
{column.map((image, imageIndex) =>
{column.map((image, imageIndex) => (
<img key={imageIndex} className={styles.image} src={image} />
)}
))}
</div>
)}
</div>;
))}
</div>
);

Gallery.propTypes = {
columns: PropTypes.number,
Expand Down Expand Up @@ -71,19 +72,17 @@ const Demo = ({ location }) => {
</div>

<div className={styles.panes}>
{demoRoutes.map(route =>
{demoRoutes.map(route => (
<Fragment key={route} forRoute={route}>
<div>
<p>
{location.result && location.result.text}
</p>
<p>{location.result && location.result.text}</p>
<Gallery
images={location.result && location.result.images}
columns={COLUMN_COUNT}
/>
</div>
</Fragment>
)}
))}
</div>

<Fragment forRoute="/">
Expand Down
5 changes: 3 additions & 2 deletions demo/client/wrap.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import { Provider } from 'react-redux';

export default store => Root =>
export default store => Root => (
<Provider store={store}>
<Root />
</Provider>;
</Provider>
);
Loading

0 comments on commit 3509647

Please sign in to comment.