Create synapse-admin using 'rekit create --sass synapse-admin'
Change-Id: I14a94754264c83faffb7fea5099d37c97e60b07a
This commit is contained in:
parent
427e91d123
commit
00d6959927
4
.babelrc
Normal file
4
.babelrc
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"presets": ["react-app"],
|
||||
"plugins": ["react-hot-loader/babel", "syntax-dynamic-import", "lodash"]
|
||||
}
|
5
.editorconfig
Normal file
5
.editorconfig
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
indent_style: 'space',
|
||||
indent_size: 2,
|
||||
tab_width: 2
|
||||
};
|
21
.gitignore
vendored
Normal file
21
.gitignore
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
# See https://help.github.com/ignore-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
5
.prettierrc
Normal file
5
.prettierrc
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all",
|
||||
"printWidth": 100
|
||||
}
|
93
config/env.js
Normal file
93
config/env.js
Normal file
@ -0,0 +1,93 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const paths = require('./paths');
|
||||
|
||||
// Make sure that including paths.js after env.js will read .env variables.
|
||||
delete require.cache[require.resolve('./paths')];
|
||||
|
||||
const NODE_ENV = process.env.NODE_ENV;
|
||||
if (!NODE_ENV) {
|
||||
throw new Error(
|
||||
'The NODE_ENV environment variable is required but was not specified.'
|
||||
);
|
||||
}
|
||||
|
||||
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
|
||||
var dotenvFiles = [
|
||||
`${paths.dotenv}.${NODE_ENV}.local`,
|
||||
`${paths.dotenv}.${NODE_ENV}`,
|
||||
// Don't include `.env.local` for `test` environment
|
||||
// since normally you expect tests to produce the same
|
||||
// results for everyone
|
||||
NODE_ENV !== 'test' && `${paths.dotenv}.local`,
|
||||
paths.dotenv,
|
||||
].filter(Boolean);
|
||||
|
||||
// Load environment variables from .env* files. Suppress warnings using silent
|
||||
// if this file is missing. dotenv will never modify any environment variables
|
||||
// that have already been set. Variable expansion is supported in .env files.
|
||||
// https://github.com/motdotla/dotenv
|
||||
// https://github.com/motdotla/dotenv-expand
|
||||
dotenvFiles.forEach(dotenvFile => {
|
||||
if (fs.existsSync(dotenvFile)) {
|
||||
require('dotenv-expand')(
|
||||
require('dotenv').config({
|
||||
path: dotenvFile,
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// We support resolving modules according to `NODE_PATH`.
|
||||
// This lets you use absolute paths in imports inside large monorepos:
|
||||
// https://github.com/facebookincubator/create-react-app/issues/253.
|
||||
// It works similar to `NODE_PATH` in Node itself:
|
||||
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
|
||||
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
|
||||
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
|
||||
// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421
|
||||
// We also resolve them to make sure all tools using them work consistently.
|
||||
const appDirectory = fs.realpathSync(process.cwd());
|
||||
process.env.NODE_PATH = (process.env.NODE_PATH || '')
|
||||
.split(path.delimiter)
|
||||
.filter(folder => folder && !path.isAbsolute(folder))
|
||||
.map(folder => path.resolve(appDirectory, folder))
|
||||
.join(path.delimiter);
|
||||
|
||||
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
|
||||
// injected into the application via DefinePlugin in Webpack configuration.
|
||||
const REACT_APP = /^REACT_APP_/i;
|
||||
|
||||
function getClientEnvironment(publicUrl) {
|
||||
const raw = Object.keys(process.env)
|
||||
.filter(key => REACT_APP.test(key))
|
||||
.reduce(
|
||||
(env, key) => {
|
||||
env[key] = process.env[key];
|
||||
return env;
|
||||
},
|
||||
{
|
||||
// Useful for determining whether we’re running in production mode.
|
||||
// Most importantly, it switches React into the correct mode.
|
||||
NODE_ENV: process.env.NODE_ENV || 'development',
|
||||
// Useful for resolving the correct path to static assets in `public`.
|
||||
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
|
||||
// This should only be used as an escape hatch. Normally you would put
|
||||
// images into the `src` and `import` them in code to get their paths.
|
||||
PUBLIC_URL: publicUrl,
|
||||
}
|
||||
);
|
||||
// Stringify all values so we can feed into Webpack DefinePlugin
|
||||
const stringified = {
|
||||
'process.env': Object.keys(raw).reduce((env, key) => {
|
||||
env[key] = JSON.stringify(raw[key]);
|
||||
return env;
|
||||
}, {}),
|
||||
};
|
||||
|
||||
return { raw, stringified };
|
||||
}
|
||||
|
||||
module.exports = getClientEnvironment;
|
14
config/jest/cssTransform.js
Normal file
14
config/jest/cssTransform.js
Normal file
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
// This is a custom Jest transformer turning style imports into empty objects.
|
||||
// http://facebook.github.io/jest/docs/en/webpack.html
|
||||
|
||||
module.exports = {
|
||||
process() {
|
||||
return 'module.exports = {};';
|
||||
},
|
||||
getCacheKey() {
|
||||
// The output is always the same.
|
||||
return 'cssTransform';
|
||||
},
|
||||
};
|
12
config/jest/fileTransform.js
Normal file
12
config/jest/fileTransform.js
Normal file
@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
|
||||
// This is a custom Jest transformer turning file imports into filenames.
|
||||
// http://facebook.github.io/jest/docs/en/webpack.html
|
||||
|
||||
module.exports = {
|
||||
process(src, filename) {
|
||||
return `module.exports = ${JSON.stringify(path.basename(filename))};`;
|
||||
},
|
||||
};
|
56
config/paths.js
Normal file
56
config/paths.js
Normal file
@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const url = require('url');
|
||||
|
||||
// Make sure any symlinks in the project folder are resolved:
|
||||
// https://github.com/facebookincubator/create-react-app/issues/637
|
||||
const appDirectory = fs.realpathSync(process.cwd());
|
||||
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
|
||||
|
||||
const envPublicUrl = process.env.PUBLIC_URL;
|
||||
|
||||
function ensureSlash(path, needsSlash) {
|
||||
const hasSlash = path.endsWith('/');
|
||||
if (hasSlash && !needsSlash) {
|
||||
return path.substr(path, path.length - 1);
|
||||
} else if (!hasSlash && needsSlash) {
|
||||
return `${path}/`;
|
||||
} else {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
const getPublicUrl = appPackageJson =>
|
||||
envPublicUrl || require(appPackageJson).homepage;
|
||||
|
||||
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
|
||||
// "public path" at which the app is served.
|
||||
// Webpack needs to know it to put the right <script> hrefs into HTML even in
|
||||
// single-page apps that may serve index.html for nested URLs like /todos/42.
|
||||
// We can't use a relative path in HTML because we don't want to load something
|
||||
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
|
||||
function getServedPath(appPackageJson) {
|
||||
const publicUrl = getPublicUrl(appPackageJson);
|
||||
const servedUrl =
|
||||
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
|
||||
return ensureSlash(servedUrl, true);
|
||||
}
|
||||
|
||||
// config after eject: we're in ./config/
|
||||
module.exports = {
|
||||
dotenv: resolveApp('.env'),
|
||||
appBuild: resolveApp('build'),
|
||||
appPublic: resolveApp('public'),
|
||||
appHtml: resolveApp('public/index.html'),
|
||||
appIndexJs: resolveApp('src/index.js'),
|
||||
appIndexStyle: resolveApp('src/styles/index.scss'),
|
||||
appPackageJson: resolveApp('package.json'),
|
||||
appSrc: resolveApp('src'),
|
||||
yarnLockFile: resolveApp('yarn.lock'),
|
||||
testsSetup: resolveApp('src/setupTests.js'),
|
||||
appNodeModules: resolveApp('node_modules'),
|
||||
publicUrl: getPublicUrl(resolveApp('package.json')),
|
||||
servedPath: getServedPath(resolveApp('package.json')),
|
||||
};
|
22
config/polyfills.js
Normal file
22
config/polyfills.js
Normal file
@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
if (typeof Promise === 'undefined') {
|
||||
// Rejection tracking prevents a common issue where React gets into an
|
||||
// inconsistent state due to an error, but it gets swallowed by a Promise,
|
||||
// and the user has no idea what causes React's erratic future behavior.
|
||||
require('promise/lib/rejection-tracking').enable();
|
||||
window.Promise = require('promise/lib/es6-extensions.js');
|
||||
}
|
||||
|
||||
// fetch() polyfill for making API calls.
|
||||
require('whatwg-fetch');
|
||||
|
||||
// Object.assign() is commonly used with React.
|
||||
// It will use the native implementation if it's present and isn't buggy.
|
||||
Object.assign = require('object-assign');
|
||||
|
||||
// In tests, polyfill requestAnimationFrame since jsdom doesn't provide it yet.
|
||||
// We don't polyfill it in the browser--this is user's responsibility.
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
require('raf').polyfill(global);
|
||||
}
|
267
config/webpack.config.dev.js
Normal file
267
config/webpack.config.dev.js
Normal file
@ -0,0 +1,267 @@
|
||||
'use strict';
|
||||
|
||||
const autoprefixer = require('autoprefixer');
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
|
||||
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
|
||||
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
|
||||
const eslintFormatter = require('react-dev-utils/eslintFormatter');
|
||||
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
||||
const getClientEnvironment = require('./env');
|
||||
const paths = require('./paths');
|
||||
|
||||
// Webpack uses `publicPath` to determine where the app is being served from.
|
||||
// In development, we always serve from the root. This makes config easier.
|
||||
const publicPath = '/';
|
||||
// `publicUrl` is just like `publicPath`, but we will provide it to our app
|
||||
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
||||
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
|
||||
const publicUrl = '';
|
||||
// Get environment variables to inject into our app.
|
||||
const env = getClientEnvironment(publicUrl);
|
||||
|
||||
// This is the development configuration.
|
||||
// It is focused on developer experience and fast rebuilds.
|
||||
// The production configuration is different and lives in a separate file.
|
||||
module.exports = {
|
||||
// You may want 'eval' instead if you prefer to see the compiled output in DevTools.
|
||||
// See the discussion in https://github.com/facebookincubator/create-react-app/issues/343.
|
||||
devtool: 'cheap-module-source-map',
|
||||
// These are the "entry points" to our application.
|
||||
// This means they will be the "root" imports that are included in JS bundle.
|
||||
// The first two entry points enable "hot" CSS and auto-refreshes for JS.
|
||||
entry: [
|
||||
// We ship a few polyfills by default:
|
||||
require.resolve('./polyfills'),
|
||||
// Include an alternative client for WebpackDevServer. A client's job is to
|
||||
// connect to WebpackDevServer by a socket and get notified about changes.
|
||||
// When you save a file, the client will either apply hot updates (in case
|
||||
// of CSS changes), or refresh the page (in case of JS changes). When you
|
||||
// make a syntax error, this client will display a syntax error overlay.
|
||||
// Note: instead of the default WebpackDevServer client, we use a custom one
|
||||
// to bring better experience for Create React App users. You can replace
|
||||
// the line below with these two lines if you prefer the stock client:
|
||||
// require.resolve('webpack-dev-server/client') + '?/',
|
||||
// require.resolve('webpack/hot/dev-server'),
|
||||
require.resolve('react-dev-utils/webpackHotDevClient'),
|
||||
// Finally, this is your app's code:
|
||||
paths.appIndexJs,
|
||||
paths.appIndexStyle,
|
||||
// We include the app code last so that if there is a runtime error during
|
||||
// initialization, it doesn't blow up the WebpackDevServer client, and
|
||||
// changing JS code would still trigger a refresh.
|
||||
],
|
||||
output: {
|
||||
// Add /* filename */ comments to generated require()s in the output.
|
||||
pathinfo: true,
|
||||
// This does not produce a real file. It's just the virtual path that is
|
||||
// served by WebpackDevServer in development. This is the JS bundle
|
||||
// containing code from all our entry points, and the Webpack runtime.
|
||||
filename: 'static/js/bundle.js',
|
||||
// There are also additional JS chunk files if you use code splitting.
|
||||
chunkFilename: 'static/js/[name].chunk.js',
|
||||
// This is the URL that app is served from. We use "/" in development.
|
||||
publicPath: publicPath,
|
||||
// Point sourcemap entries to original disk location (format as URL on Windows)
|
||||
devtoolModuleFilenameTemplate: info =>
|
||||
path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'),
|
||||
},
|
||||
resolve: {
|
||||
// This allows you to set a fallback for where Webpack should look for modules.
|
||||
// We placed these paths second because we want `node_modules` to "win"
|
||||
// if there are any conflicts. This matches Node resolution mechanism.
|
||||
// https://github.com/facebookincubator/create-react-app/issues/253
|
||||
modules: ['node_modules', paths.appNodeModules].concat(
|
||||
// It is guaranteed to exist because we tweak it in `env.js`
|
||||
process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
|
||||
),
|
||||
// These are the reasonable defaults supported by the Node ecosystem.
|
||||
// We also include JSX as a common component filename extension to support
|
||||
// some tools, although we do not recommend using it, see:
|
||||
// https://github.com/facebookincubator/create-react-app/issues/290
|
||||
// `web` extension prefixes have been added for better support
|
||||
// for React Native Web.
|
||||
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
|
||||
alias: {
|
||||
|
||||
// Support React Native Web
|
||||
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
||||
'react-native': 'react-native-web',
|
||||
},
|
||||
plugins: [
|
||||
// Prevents users from importing files from outside of src/ (or node_modules/).
|
||||
// This often causes confusion because we only process files within src/ with babel.
|
||||
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
||||
// please link the files into your node_modules/ and let module-resolution kick in.
|
||||
// Make sure your source files are compiled, as they will not be processed in any way.
|
||||
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
|
||||
],
|
||||
},
|
||||
module: {
|
||||
strictExportPresence: true,
|
||||
rules: [
|
||||
// TODO: Disable require.ensure as it's not a standard language feature.
|
||||
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
|
||||
// { parser: { requireEnsure: false } },
|
||||
|
||||
// First, run the linter.
|
||||
// It's important to do this before Babel processes the JS.
|
||||
{
|
||||
test: /\.(js|jsx|mjs)$/,
|
||||
enforce: 'pre',
|
||||
use: [
|
||||
{
|
||||
options: {
|
||||
formatter: eslintFormatter,
|
||||
eslintPath: require.resolve('eslint'),
|
||||
|
||||
},
|
||||
loader: require.resolve('eslint-loader'),
|
||||
},
|
||||
],
|
||||
include: paths.appSrc,
|
||||
},
|
||||
{
|
||||
// "oneOf" will traverse all following loaders until one will
|
||||
// match the requirements. When no loader matches it will fall
|
||||
// back to the "file" loader at the end of the loader list.
|
||||
oneOf: [
|
||||
// "url" loader works like "file" loader except that it embeds assets
|
||||
// smaller than specified limit in bytes as data URLs to avoid requests.
|
||||
// A missing `test` is equivalent to a match.
|
||||
{
|
||||
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
|
||||
loader: require.resolve('url-loader'),
|
||||
options: {
|
||||
limit: 10000,
|
||||
name: 'static/media/[name].[hash:8].[ext]',
|
||||
},
|
||||
},
|
||||
// Process JS with Babel.
|
||||
{
|
||||
test: /\.(js|jsx|mjs)$/,
|
||||
include: paths.appSrc,
|
||||
loader: require.resolve('babel-loader'),
|
||||
options: {
|
||||
|
||||
// This is a feature of `babel-loader` for webpack (not Babel itself).
|
||||
// It enables caching results in ./node_modules/.cache/babel-loader/
|
||||
// directory for faster rebuilds.
|
||||
cacheDirectory: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
loader: 'style-loader!css-loader?sourceMap!sass-loader?sourceMap'
|
||||
},
|
||||
// "postcss" loader applies autoprefixer to our CSS.
|
||||
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
||||
// "style" loader turns CSS into JS modules that inject <style> tags.
|
||||
// In production, we use a plugin to extract that CSS to a file, but
|
||||
// in development "style" loader enables hot editing of CSS.
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [
|
||||
require.resolve('style-loader'),
|
||||
{
|
||||
loader: require.resolve('css-loader'),
|
||||
options: {
|
||||
importLoaders: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
loader: require.resolve('postcss-loader'),
|
||||
options: {
|
||||
// Necessary for external CSS imports to work
|
||||
// https://github.com/facebookincubator/create-react-app/issues/2677
|
||||
ident: 'postcss',
|
||||
plugins: () => [
|
||||
require('postcss-flexbugs-fixes'),
|
||||
autoprefixer({
|
||||
browsers: [
|
||||
'>1%',
|
||||
'last 4 versions',
|
||||
'Firefox ESR',
|
||||
'not ie < 9', // React doesn't support IE8 anyway
|
||||
],
|
||||
flexbox: 'no-2009',
|
||||
}),
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
// "file" loader makes sure those assets get served by WebpackDevServer.
|
||||
// When you `import` an asset, you get its (virtual) filename.
|
||||
// In production, they would get copied to the `build` folder.
|
||||
// This loader doesn't use a "test" so it will catch all modules
|
||||
// that fall through the other loaders.
|
||||
{
|
||||
// Exclude `js` files to keep "css" loader working as it injects
|
||||
// its runtime that would otherwise processed through "file" loader.
|
||||
// Also exclude `html` and `json` extensions so they get processed
|
||||
// by webpacks internal loaders.
|
||||
exclude: [/\.(js|jsx|mjs)$/, /\.html$/, /\.json$/],
|
||||
loader: require.resolve('file-loader'),
|
||||
options: {
|
||||
name: 'static/media/[name].[hash:8].[ext]',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
// ** STOP ** Are you adding a new loader?
|
||||
// Make sure to add the new loader(s) before the "file" loader.
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
// Makes some environment variables available in index.html.
|
||||
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
|
||||
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||
// In development, this will be an empty string.
|
||||
new InterpolateHtmlPlugin(env.raw),
|
||||
// Generates an `index.html` file with the <script> injected.
|
||||
new HtmlWebpackPlugin({
|
||||
inject: true,
|
||||
template: paths.appHtml,
|
||||
}),
|
||||
// Add module names to factory functions so they appear in browser profiler.
|
||||
new webpack.NamedModulesPlugin(),
|
||||
// Makes some environment variables available to the JS code, for example:
|
||||
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
|
||||
new webpack.DefinePlugin(env.stringified),
|
||||
// This is necessary to emit hot updates (currently CSS only):
|
||||
new webpack.HotModuleReplacementPlugin(),
|
||||
// Watcher doesn't work well if you mistype casing in a path so we use
|
||||
// a plugin that prints an error when you attempt to do this.
|
||||
// See https://github.com/facebookincubator/create-react-app/issues/240
|
||||
new CaseSensitivePathsPlugin(),
|
||||
// If you require a missing module and then `npm install` it, you still have
|
||||
// to restart the development server for Webpack to discover it. This plugin
|
||||
// makes the discovery automatic so you don't have to restart.
|
||||
// See https://github.com/facebookincubator/create-react-app/issues/186
|
||||
new WatchMissingNodeModulesPlugin(paths.appNodeModules),
|
||||
// Moment.js is an extremely popular library that bundles large locale files
|
||||
// by default due to how Webpack interprets its code. This is a practical
|
||||
// solution that requires the user to opt into importing specific locales.
|
||||
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
||||
// You can remove this if you don't use Moment.js:
|
||||
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
||||
],
|
||||
// Some libraries import Node modules but don't use them in the browser.
|
||||
// Tell Webpack to provide empty mocks for them so importing them works.
|
||||
node: {
|
||||
dgram: 'empty',
|
||||
fs: 'empty',
|
||||
net: 'empty',
|
||||
tls: 'empty',
|
||||
child_process: 'empty',
|
||||
},
|
||||
// Turn off performance hints during development because we don't do any
|
||||
// splitting or minification in interest of speed. These warnings become
|
||||
// cumbersome.
|
||||
performance: {
|
||||
hints: false,
|
||||
},
|
||||
};
|
346
config/webpack.config.prod.js
Normal file
346
config/webpack.config.prod.js
Normal file
@ -0,0 +1,346 @@
|
||||
'use strict';
|
||||
|
||||
const autoprefixer = require('autoprefixer');
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||
const ManifestPlugin = require('webpack-manifest-plugin');
|
||||
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
|
||||
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
|
||||
const eslintFormatter = require('react-dev-utils/eslintFormatter');
|
||||
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
||||
const paths = require('./paths');
|
||||
const getClientEnvironment = require('./env');
|
||||
|
||||
// Webpack uses `publicPath` to determine where the app is being served from.
|
||||
// It requires a trailing slash, or the file assets will get an incorrect path.
|
||||
const publicPath = paths.servedPath;
|
||||
// Some apps do not use client-side routing with pushState.
|
||||
// For these, "homepage" can be set to "." to enable relative asset paths.
|
||||
const shouldUseRelativeAssetPaths = publicPath === './';
|
||||
// Source maps are resource heavy and can cause out of memory issue for large source files.
|
||||
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
|
||||
// `publicUrl` is just like `publicPath`, but we will provide it to our app
|
||||
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
||||
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
|
||||
const publicUrl = publicPath.slice(0, -1);
|
||||
// Get environment variables to inject into our app.
|
||||
const env = getClientEnvironment(publicUrl);
|
||||
|
||||
// Assert this just to be safe.
|
||||
// Development builds of React are slow and not intended for production.
|
||||
if (env.stringified['process.env'].NODE_ENV !== '"production"') {
|
||||
throw new Error('Production builds must have NODE_ENV=production.');
|
||||
}
|
||||
|
||||
// Note: defined here because it will be used more than once.
|
||||
const cssFilename = 'static/css/[name].[contenthash:8].css';
|
||||
|
||||
// ExtractTextPlugin expects the build output to be flat.
|
||||
// (See https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/27)
|
||||
// However, our output is structured with css, js and media folders.
|
||||
// To have this structure working with relative paths, we have to use custom options.
|
||||
const extractTextPluginOptions = shouldUseRelativeAssetPaths
|
||||
? // Making sure that the publicPath goes back to to build folder.
|
||||
{ publicPath: Array(cssFilename.split('/').length).join('../') }
|
||||
: {};
|
||||
|
||||
// This is the production configuration.
|
||||
// It compiles slowly and is focused on producing a fast and minimal bundle.
|
||||
// The development configuration is different and lives in a separate file.
|
||||
module.exports = {
|
||||
// Don't attempt to continue if there are any errors.
|
||||
bail: true,
|
||||
// We generate sourcemaps in production. This is slow but gives good results.
|
||||
// You can exclude the *.map files from the build during deployment.
|
||||
devtool: shouldUseSourceMap ? 'source-map' : false,
|
||||
// In production, we only want to load the polyfills and the app code.
|
||||
entry: [require.resolve('./polyfills'), paths.appIndexJs, paths.appIndexStyle],
|
||||
output: {
|
||||
// The build folder.
|
||||
path: paths.appBuild,
|
||||
// Generated JS file names (with nested folders).
|
||||
// There will be one main bundle, and one file per asynchronous chunk.
|
||||
// We don't currently advertise code splitting but Webpack supports it.
|
||||
filename: 'static/js/[name].[chunkhash:8].js',
|
||||
chunkFilename: 'static/js/[name].[chunkhash:8].chunk.js',
|
||||
// We inferred the "public path" (such as / or /my-project) from homepage.
|
||||
publicPath: publicPath,
|
||||
// Point sourcemap entries to original disk location (format as URL on Windows)
|
||||
devtoolModuleFilenameTemplate: info =>
|
||||
path
|
||||
.relative(paths.appSrc, info.absoluteResourcePath)
|
||||
.replace(/\\/g, '/'),
|
||||
},
|
||||
resolve: {
|
||||
// This allows you to set a fallback for where Webpack should look for modules.
|
||||
// We placed these paths second because we want `node_modules` to "win"
|
||||
// if there are any conflicts. This matches Node resolution mechanism.
|
||||
// https://github.com/facebookincubator/create-react-app/issues/253
|
||||
modules: ['node_modules', paths.appNodeModules].concat(
|
||||
// It is guaranteed to exist because we tweak it in `env.js`
|
||||
process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
|
||||
),
|
||||
// These are the reasonable defaults supported by the Node ecosystem.
|
||||
// We also include JSX as a common component filename extension to support
|
||||
// some tools, although we do not recommend using it, see:
|
||||
// https://github.com/facebookincubator/create-react-app/issues/290
|
||||
// `web` extension prefixes have been added for better support
|
||||
// for React Native Web.
|
||||
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
|
||||
alias: {
|
||||
|
||||
// Support React Native Web
|
||||
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
||||
'react-native': 'react-native-web',
|
||||
},
|
||||
plugins: [
|
||||
// Prevents users from importing files from outside of src/ (or node_modules/).
|
||||
// This often causes confusion because we only process files within src/ with babel.
|
||||
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
||||
// please link the files into your node_modules/ and let module-resolution kick in.
|
||||
// Make sure your source files are compiled, as they will not be processed in any way.
|
||||
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
|
||||
],
|
||||
},
|
||||
module: {
|
||||
strictExportPresence: true,
|
||||
rules: [
|
||||
// TODO: Disable require.ensure as it's not a standard language feature.
|
||||
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
|
||||
// { parser: { requireEnsure: false } },
|
||||
|
||||
// First, run the linter.
|
||||
// It's important to do this before Babel processes the JS.
|
||||
{
|
||||
test: /\.(js|jsx|mjs)$/,
|
||||
enforce: 'pre',
|
||||
use: [
|
||||
{
|
||||
options: {
|
||||
formatter: eslintFormatter,
|
||||
eslintPath: require.resolve('eslint'),
|
||||
|
||||
},
|
||||
loader: require.resolve('eslint-loader'),
|
||||
},
|
||||
],
|
||||
include: paths.appSrc,
|
||||
},
|
||||
{
|
||||
// "oneOf" will traverse all following loaders until one will
|
||||
// match the requirements. When no loader matches it will fall
|
||||
// back to the "file" loader at the end of the loader list.
|
||||
oneOf: [
|
||||
// "url" loader works just like "file" loader but it also embeds
|
||||
// assets smaller than specified size as data URLs to avoid requests.
|
||||
{
|
||||
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
|
||||
loader: require.resolve('url-loader'),
|
||||
options: {
|
||||
limit: 10000,
|
||||
name: 'static/media/[name].[hash:8].[ext]',
|
||||
},
|
||||
},
|
||||
// Process JS with Babel.
|
||||
{
|
||||
test: /\.(js|jsx|mjs)$/,
|
||||
include: paths.appSrc,
|
||||
loader: require.resolve('babel-loader'),
|
||||
options: {
|
||||
|
||||
compact: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
loader: 'style-loader!css-loader!sass-loader'
|
||||
},
|
||||
// The notation here is somewhat confusing.
|
||||
// "postcss" loader applies autoprefixer to our CSS.
|
||||
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
||||
// "style" loader normally turns CSS into JS modules injecting <style>,
|
||||
// but unlike in development configuration, we do something different.
|
||||
// `ExtractTextPlugin` first applies the "postcss" and "css" loaders
|
||||
// (second argument), then grabs the result CSS and puts it into a
|
||||
// separate file in our build process. This way we actually ship
|
||||
// a single CSS file in production instead of JS code injecting <style>
|
||||
// tags. If you use code splitting, however, any async bundles will still
|
||||
// use the "style" loader inside the async code so CSS from them won't be
|
||||
// in the main CSS file.
|
||||
{
|
||||
test: /\.css$/,
|
||||
loader: ExtractTextPlugin.extract(
|
||||
Object.assign(
|
||||
{
|
||||
fallback: {
|
||||
loader: require.resolve('style-loader'),
|
||||
options: {
|
||||
hmr: false,
|
||||
},
|
||||
},
|
||||
use: [
|
||||
{
|
||||
loader: require.resolve('css-loader'),
|
||||
options: {
|
||||
importLoaders: 1,
|
||||
minimize: true,
|
||||
sourceMap: shouldUseSourceMap,
|
||||
},
|
||||
},
|
||||
{
|
||||
loader: require.resolve('postcss-loader'),
|
||||
options: {
|
||||
// Necessary for external CSS imports to work
|
||||
// https://github.com/facebookincubator/create-react-app/issues/2677
|
||||
ident: 'postcss',
|
||||
plugins: () => [
|
||||
require('postcss-flexbugs-fixes'),
|
||||
autoprefixer({
|
||||
browsers: [
|
||||
'>1%',
|
||||
'last 4 versions',
|
||||
'Firefox ESR',
|
||||
'not ie < 9', // React doesn't support IE8 anyway
|
||||
],
|
||||
flexbox: 'no-2009',
|
||||
}),
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
extractTextPluginOptions
|
||||
)
|
||||
),
|
||||
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
|
||||
},
|
||||
// "file" loader makes sure assets end up in the `build` folder.
|
||||
// When you `import` an asset, you get its filename.
|
||||
// This loader doesn't use a "test" so it will catch all modules
|
||||
// that fall through the other loaders.
|
||||
{
|
||||
loader: require.resolve('file-loader'),
|
||||
// Exclude `js` files to keep "css" loader working as it injects
|
||||
// it's runtime that would otherwise processed through "file" loader.
|
||||
// Also exclude `html` and `json` extensions so they get processed
|
||||
// by webpacks internal loaders.
|
||||
exclude: [/\.(js|jsx|mjs)$/, /\.html$/, /\.json$/],
|
||||
options: {
|
||||
name: 'static/media/[name].[hash:8].[ext]',
|
||||
},
|
||||
},
|
||||
// ** STOP ** Are you adding a new loader?
|
||||
// Make sure to add the new loader(s) before the "file" loader.
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
// Makes some environment variables available in index.html.
|
||||
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
|
||||
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||
// In production, it will be an empty string unless you specify "homepage"
|
||||
// in `package.json`, in which case it will be the pathname of that URL.
|
||||
new InterpolateHtmlPlugin(env.raw),
|
||||
// Generates an `index.html` file with the <script> injected.
|
||||
new HtmlWebpackPlugin({
|
||||
inject: true,
|
||||
template: paths.appHtml,
|
||||
minify: {
|
||||
removeComments: true,
|
||||
collapseWhitespace: true,
|
||||
removeRedundantAttributes: true,
|
||||
useShortDoctype: true,
|
||||
removeEmptyAttributes: true,
|
||||
removeStyleLinkTypeAttributes: true,
|
||||
keepClosingSlash: true,
|
||||
minifyJS: true,
|
||||
minifyCSS: true,
|
||||
minifyURLs: true,
|
||||
},
|
||||
}),
|
||||
// Makes some environment variables available to the JS code, for example:
|
||||
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
|
||||
// It is absolutely essential that NODE_ENV was set to production here.
|
||||
// Otherwise React will be compiled in the very slow development mode.
|
||||
new webpack.DefinePlugin(env.stringified),
|
||||
// Minify the code.
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
compress: {
|
||||
warnings: false,
|
||||
// Disabled because of an issue with Uglify breaking seemingly valid code:
|
||||
// https://github.com/facebookincubator/create-react-app/issues/2376
|
||||
// Pending further investigation:
|
||||
// https://github.com/mishoo/UglifyJS2/issues/2011
|
||||
comparisons: false,
|
||||
},
|
||||
mangle: {
|
||||
safari10: true,
|
||||
},
|
||||
output: {
|
||||
comments: false,
|
||||
// Turned on because emoji and regex is not minified properly using default
|
||||
// https://github.com/facebookincubator/create-react-app/issues/2488
|
||||
ascii_only: true,
|
||||
},
|
||||
sourceMap: shouldUseSourceMap,
|
||||
}),
|
||||
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
|
||||
new ExtractTextPlugin({
|
||||
filename: cssFilename,
|
||||
}),
|
||||
// Generate a manifest file which contains a mapping of all asset filenames
|
||||
// to their corresponding output file so that tools can pick it up without
|
||||
// having to parse `index.html`.
|
||||
new ManifestPlugin({
|
||||
fileName: 'asset-manifest.json',
|
||||
}),
|
||||
// Generate a service worker script that will precache, and keep up to date,
|
||||
// the HTML & assets that are part of the Webpack build.
|
||||
new SWPrecacheWebpackPlugin({
|
||||
// By default, a cache-busting query parameter is appended to requests
|
||||
// used to populate the caches, to ensure the responses are fresh.
|
||||
// If a URL is already hashed by Webpack, then there is no concern
|
||||
// about it being stale, and the cache-busting can be skipped.
|
||||
dontCacheBustUrlsMatching: /\.\w{8}\./,
|
||||
filename: 'service-worker.js',
|
||||
logger(message) {
|
||||
if (message.indexOf('Total precache size is') === 0) {
|
||||
// This message occurs for every build and is a bit too noisy.
|
||||
return;
|
||||
}
|
||||
if (message.indexOf('Skipping static resource') === 0) {
|
||||
// This message obscures real errors so we ignore it.
|
||||
// https://github.com/facebookincubator/create-react-app/issues/2612
|
||||
return;
|
||||
}
|
||||
console.log(message);
|
||||
},
|
||||
minify: true,
|
||||
// For unknown URLs, fallback to the index page
|
||||
navigateFallback: publicUrl + '/index.html',
|
||||
// Ignores URLs starting from /__ (useful for Firebase):
|
||||
// https://github.com/facebookincubator/create-react-app/issues/2237#issuecomment-302693219
|
||||
navigateFallbackWhitelist: [/^(?!\/__).*/],
|
||||
// Don't precache sourcemaps (they're large) and build asset manifest:
|
||||
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/],
|
||||
}),
|
||||
// Moment.js is an extremely popular library that bundles large locale files
|
||||
// by default due to how Webpack interprets its code. This is a practical
|
||||
// solution that requires the user to opt into importing specific locales.
|
||||
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
||||
// You can remove this if you don't use Moment.js:
|
||||
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
||||
],
|
||||
// Some libraries import Node modules but don't use them in the browser.
|
||||
// Tell Webpack to provide empty mocks for them so importing them works.
|
||||
node: {
|
||||
dgram: 'empty',
|
||||
fs: 'empty',
|
||||
net: 'empty',
|
||||
tls: 'empty',
|
||||
child_process: 'empty',
|
||||
},
|
||||
};
|
95
config/webpackDevServer.config.js
Normal file
95
config/webpackDevServer.config.js
Normal file
@ -0,0 +1,95 @@
|
||||
'use strict';
|
||||
|
||||
const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');
|
||||
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
|
||||
const ignoredFiles = require('react-dev-utils/ignoredFiles');
|
||||
const config = require('./webpack.config.dev');
|
||||
const paths = require('./paths');
|
||||
|
||||
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
||||
const host = process.env.HOST || '0.0.0.0';
|
||||
|
||||
module.exports = function(proxy, allowedHost) {
|
||||
return {
|
||||
// WebpackDevServer 2.4.3 introduced a security fix that prevents remote
|
||||
// websites from potentially accessing local content through DNS rebinding:
|
||||
// https://github.com/webpack/webpack-dev-server/issues/887
|
||||
// https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a
|
||||
// However, it made several existing use cases such as development in cloud
|
||||
// environment or subdomains in development significantly more complicated:
|
||||
// https://github.com/facebookincubator/create-react-app/issues/2271
|
||||
// https://github.com/facebookincubator/create-react-app/issues/2233
|
||||
// While we're investigating better solutions, for now we will take a
|
||||
// compromise. Since our WDS configuration only serves files in the `public`
|
||||
// folder we won't consider accessing them a vulnerability. However, if you
|
||||
// use the `proxy` feature, it gets more dangerous because it can expose
|
||||
// remote code execution vulnerabilities in backends like Django and Rails.
|
||||
// So we will disable the host check normally, but enable it if you have
|
||||
// specified the `proxy` setting. Finally, we let you override it if you
|
||||
// really know what you're doing with a special environment variable.
|
||||
disableHostCheck:
|
||||
!proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true',
|
||||
// Enable gzip compression of generated files.
|
||||
compress: true,
|
||||
// Silence WebpackDevServer's own logs since they're generally not useful.
|
||||
// It will still show compile warnings and errors with this setting.
|
||||
clientLogLevel: 'none',
|
||||
// By default WebpackDevServer serves physical files from current directory
|
||||
// in addition to all the virtual build products that it serves from memory.
|
||||
// This is confusing because those files won’t automatically be available in
|
||||
// production build folder unless we copy them. However, copying the whole
|
||||
// project directory is dangerous because we may expose sensitive files.
|
||||
// Instead, we establish a convention that only files in `public` directory
|
||||
// get served. Our build script will copy `public` into the `build` folder.
|
||||
// In `index.html`, you can get URL of `public` folder with %PUBLIC_URL%:
|
||||
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||
// In JavaScript code, you can access it with `process.env.PUBLIC_URL`.
|
||||
// Note that we only recommend to use `public` folder as an escape hatch
|
||||
// for files like `favicon.ico`, `manifest.json`, and libraries that are
|
||||
// for some reason broken when imported through Webpack. If you just want to
|
||||
// use an image, put it in `src` and `import` it from JavaScript instead.
|
||||
contentBase: paths.appPublic,
|
||||
// By default files from `contentBase` will not trigger a page reload.
|
||||
watchContentBase: true,
|
||||
// Enable hot reloading server. It will provide /sockjs-node/ endpoint
|
||||
// for the WebpackDevServer client so it can learn when the files were
|
||||
// updated. The WebpackDevServer client is included as an entry point
|
||||
// in the Webpack development configuration. Note that only changes
|
||||
// to CSS are currently hot reloaded. JS changes will refresh the browser.
|
||||
hot: true,
|
||||
// It is important to tell WebpackDevServer to use the same "root" path
|
||||
// as we specified in the config. In development, we always serve from /.
|
||||
publicPath: config.output.publicPath,
|
||||
// WebpackDevServer is noisy by default so we emit custom message instead
|
||||
// by listening to the compiler events with `compiler.plugin` calls above.
|
||||
quiet: true,
|
||||
// Reportedly, this avoids CPU overload on some systems.
|
||||
// https://github.com/facebookincubator/create-react-app/issues/293
|
||||
// src/node_modules is not ignored to support absolute imports
|
||||
// https://github.com/facebookincubator/create-react-app/issues/1065
|
||||
watchOptions: {
|
||||
ignored: ignoredFiles(paths.appSrc),
|
||||
},
|
||||
// Enable HTTPS if the HTTPS environment variable is set to 'true'
|
||||
https: protocol === 'https',
|
||||
host: host,
|
||||
overlay: false,
|
||||
historyApiFallback: {
|
||||
// Paths with dots should still use the history fallback.
|
||||
// See https://github.com/facebookincubator/create-react-app/issues/387.
|
||||
disableDotRule: true,
|
||||
},
|
||||
public: allowedHost,
|
||||
proxy,
|
||||
before(app) {
|
||||
// This lets us open files from the runtime error overlay.
|
||||
app.use(errorOverlayMiddleware());
|
||||
// This service worker file is effectively a 'no-op' that will reset any
|
||||
// previous service worker registered for the same host:port combination.
|
||||
// We do this in development to avoid hitting the production cache if
|
||||
// it used the same host and port.
|
||||
// https://github.com/facebookincubator/create-react-app/issues/2272#issuecomment-302832432
|
||||
app.use(noopServiceWorkerMiddleware());
|
||||
},
|
||||
};
|
||||
};
|
115
package.json
Normal file
115
package.json
Normal file
@ -0,0 +1,115 @@
|
||||
{
|
||||
"name": "synapse-admin",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"autoprefixer": "7.1.6",
|
||||
"axios": "^0.18.0",
|
||||
"babel-core": "6.26.0",
|
||||
"babel-eslint": "7.2.3",
|
||||
"babel-jest": "20.0.3",
|
||||
"babel-loader": "7.1.2",
|
||||
"babel-plugin-lodash": "^3.3.2",
|
||||
"babel-plugin-syntax-dynamic-import": "^6.18.0",
|
||||
"babel-preset-react-app": "^3.1.1",
|
||||
"babel-runtime": "6.26.0",
|
||||
"case-sensitive-paths-webpack-plugin": "2.1.1",
|
||||
"chalk": "1.1.3",
|
||||
"css-loader": "0.28.7",
|
||||
"dotenv": "4.0.0",
|
||||
"dotenv-expand": "4.2.0",
|
||||
"enzyme": "^3.3.0",
|
||||
"enzyme-adapter-react-16": "^1.1.1",
|
||||
"eslint": "4.10.0",
|
||||
"eslint-config-react-app": "^2.1.0",
|
||||
"eslint-loader": "1.9.0",
|
||||
"eslint-plugin-flowtype": "2.39.1",
|
||||
"eslint-plugin-import": "2.8.0",
|
||||
"eslint-plugin-jsx-a11y": "5.1.1",
|
||||
"eslint-plugin-react": "7.4.0",
|
||||
"express-history-api-fallback": "^2.2.1",
|
||||
"extract-text-webpack-plugin": "3.0.2",
|
||||
"file-loader": "1.1.5",
|
||||
"fs-extra": "3.0.1",
|
||||
"html-webpack-plugin": "2.29.0",
|
||||
"jest": "20.0.4",
|
||||
"lodash": "^4.17.5",
|
||||
"nock": "^9.2.3",
|
||||
"node-sass-chokidar": "^1.2.1",
|
||||
"object-assign": "4.1.1",
|
||||
"postcss-flexbugs-fixes": "3.2.0",
|
||||
"postcss-loader": "2.0.8",
|
||||
"promise": "8.0.1",
|
||||
"raf": "3.4.0",
|
||||
"react": "^16.2.0",
|
||||
"react-dev-utils": "^5.0.0",
|
||||
"react-dom": "^16.2.0",
|
||||
"react-hot-loader": "^4.0.0",
|
||||
"react-redux": "^5.0.7",
|
||||
"react-router-dom": "^4.2.2",
|
||||
"react-router-redux": "5.0.0-alpha.9",
|
||||
"redux": "^3.7.2",
|
||||
"redux-logger": "^3.0.6",
|
||||
"redux-mock-store": "^1.5.1",
|
||||
"redux-thunk": "^2.2.0",
|
||||
"rekit-core": "^2.3.0",
|
||||
"rekit-studio": "^2.3.0",
|
||||
"sass-loader": "^6.0.7",
|
||||
"style-loader": "0.19.0",
|
||||
"sw-precache-webpack-plugin": "0.11.4",
|
||||
"url-loader": "0.6.2",
|
||||
"webpack": "3.8.1",
|
||||
"webpack-dev-server": "2.9.4",
|
||||
"webpack-manifest-plugin": "1.3.2",
|
||||
"whatwg-fetch": "2.0.3"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node scripts/start.js",
|
||||
"build": "node scripts/build.js",
|
||||
"test": "node scripts/test.js --env=jsdom"
|
||||
},
|
||||
"rekit": {
|
||||
"devPort": 6075,
|
||||
"studioPort": 6076,
|
||||
"plugins": [],
|
||||
"css": "sass"
|
||||
},
|
||||
"jest": {
|
||||
"collectCoverageFrom": [
|
||||
"src/**/*.{js,jsx,mjs}"
|
||||
],
|
||||
"setupFiles": [
|
||||
"<rootDir>/config/polyfills.js",
|
||||
"<rootDir>/tests/setup.js"
|
||||
],
|
||||
"testMatch": [
|
||||
"<rootDir>/tests/**/*.test.{js,jsx,mjs}"
|
||||
],
|
||||
"testEnvironment": "node",
|
||||
"testURL": "http://localhost",
|
||||
"transform": {
|
||||
"^.+\\.(js|jsx|mjs)$": "<rootDir>/node_modules/babel-jest",
|
||||
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
|
||||
"^(?!.*\\.(js|jsx|mjs|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
|
||||
},
|
||||
"transformIgnorePatterns": [
|
||||
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"
|
||||
],
|
||||
"moduleNameMapper": {
|
||||
"^react-native$": "react-native-web"
|
||||
},
|
||||
"moduleFileExtensions": [
|
||||
"web.js",
|
||||
"mjs",
|
||||
"js",
|
||||
"json",
|
||||
"web.jsx",
|
||||
"jsx",
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "react-app"
|
||||
},
|
||||
"description": "synapse-admin created by Rekit."
|
||||
}
|
BIN
public/favicon.ico
Normal file
BIN
public/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
40
public/index.html
Normal file
40
public/index.html
Normal file
@ -0,0 +1,40 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="theme-color" content="#000000">
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is added to the
|
||||
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
|
||||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>
|
||||
You need to enable JavaScript to run this app.
|
||||
</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</html>
|
15
public/manifest.json
Normal file
15
public/manifest.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
}
|
||||
],
|
||||
"start_url": "./index.html",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
160
scripts/build.js
Normal file
160
scripts/build.js
Normal file
@ -0,0 +1,160 @@
|
||||
'use strict';
|
||||
|
||||
// Do this as the first thing so that any code reading it knows the right env.
|
||||
process.env.BABEL_ENV = 'production';
|
||||
process.env.NODE_ENV = 'production';
|
||||
|
||||
// Makes the script crash on unhandled rejections instead of silently
|
||||
// ignoring them. In the future, promise rejections that are not handled will
|
||||
// terminate the Node.js process with a non-zero exit code.
|
||||
process.on('unhandledRejection', err => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
// Ensure environment variables are read.
|
||||
require('../config/env');
|
||||
|
||||
const path = require('path');
|
||||
const chalk = require('chalk');
|
||||
const fs = require('fs-extra');
|
||||
const webpack = require('webpack');
|
||||
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
|
||||
const config = require('../config/webpack.config.prod');
|
||||
const paths = require('../config/paths');
|
||||
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
||||
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
|
||||
const printHostingInstructions = require('react-dev-utils/printHostingInstructions');
|
||||
const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
|
||||
const printBuildError = require('react-dev-utils/printBuildError');
|
||||
|
||||
const measureFileSizesBeforeBuild =
|
||||
FileSizeReporter.measureFileSizesBeforeBuild;
|
||||
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
|
||||
const useYarn = fs.existsSync(paths.yarnLockFile);
|
||||
|
||||
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
||||
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
||||
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
||||
|
||||
// Warn and crash if required files are missing
|
||||
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// First, read the current file sizes in build directory.
|
||||
// This lets us display how much they changed later.
|
||||
measureFileSizesBeforeBuild(paths.appBuild)
|
||||
.then(previousFileSizes => {
|
||||
// Remove all content but keep the directory so that
|
||||
// if you're in it, you don't end up in Trash
|
||||
fs.emptyDirSync(paths.appBuild);
|
||||
// Merge with the public folder
|
||||
copyPublicFolder();
|
||||
// Start the webpack build
|
||||
return build(previousFileSizes);
|
||||
})
|
||||
.then(
|
||||
({ stats, previousFileSizes, warnings }) => {
|
||||
if (warnings.length) {
|
||||
console.log(chalk.yellow('Compiled with warnings.\n'));
|
||||
console.log(warnings.join('\n\n'));
|
||||
console.log(
|
||||
'\nSearch for the ' +
|
||||
chalk.underline(chalk.yellow('keywords')) +
|
||||
' to learn more about each warning.'
|
||||
);
|
||||
console.log(
|
||||
'To ignore, add ' +
|
||||
chalk.cyan('// eslint-disable-next-line') +
|
||||
' to the line before.\n'
|
||||
);
|
||||
} else {
|
||||
console.log(chalk.green('Compiled successfully.\n'));
|
||||
}
|
||||
|
||||
console.log('File sizes after gzip:\n');
|
||||
printFileSizesAfterBuild(
|
||||
stats,
|
||||
previousFileSizes,
|
||||
paths.appBuild,
|
||||
WARN_AFTER_BUNDLE_GZIP_SIZE,
|
||||
WARN_AFTER_CHUNK_GZIP_SIZE
|
||||
);
|
||||
console.log();
|
||||
|
||||
const appPackage = require(paths.appPackageJson);
|
||||
const publicUrl = paths.publicUrl;
|
||||
const publicPath = config.output.publicPath;
|
||||
const buildFolder = path.relative(process.cwd(), paths.appBuild);
|
||||
printHostingInstructions(
|
||||
appPackage,
|
||||
publicUrl,
|
||||
publicPath,
|
||||
buildFolder,
|
||||
useYarn
|
||||
);
|
||||
},
|
||||
err => {
|
||||
console.log(chalk.red('Failed to compile.\n'));
|
||||
printBuildError(err);
|
||||
process.exit(1);
|
||||
}
|
||||
);
|
||||
|
||||
// Create the production build and print the deployment instructions.
|
||||
function build(previousFileSizes) {
|
||||
console.log('Creating an optimized production build...');
|
||||
|
||||
let compiler = webpack(config);
|
||||
let lastPercentage = 0;
|
||||
compiler.apply(new ProgressPlugin((percentage, msg) => {
|
||||
percentage = Math.round(percentage * 10000) / 100;
|
||||
if (/building modules/.test(msg) && percentage - lastPercentage < 8) {
|
||||
return;
|
||||
}
|
||||
lastPercentage = percentage;
|
||||
console.log(percentage + '%', msg);
|
||||
}));
|
||||
return new Promise((resolve, reject) => {
|
||||
compiler.run((err, stats) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
const messages = formatWebpackMessages(stats.toJson({}, true));
|
||||
if (messages.errors.length) {
|
||||
// Only keep the first error. Others are often indicative
|
||||
// of the same problem, but confuse the reader with noise.
|
||||
if (messages.errors.length > 1) {
|
||||
messages.errors.length = 1;
|
||||
}
|
||||
return reject(new Error(messages.errors.join('\n\n')));
|
||||
}
|
||||
if (
|
||||
process.env.CI &&
|
||||
(typeof process.env.CI !== 'string' ||
|
||||
process.env.CI.toLowerCase() !== 'false') &&
|
||||
messages.warnings.length
|
||||
) {
|
||||
console.log(
|
||||
chalk.yellow(
|
||||
'\nTreating warnings as errors because process.env.CI = true.\n' +
|
||||
'Most CI servers set it automatically.\n'
|
||||
)
|
||||
);
|
||||
return reject(new Error(messages.warnings.join('\n\n')));
|
||||
}
|
||||
return resolve({
|
||||
stats,
|
||||
previousFileSizes,
|
||||
warnings: messages.warnings,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function copyPublicFolder() {
|
||||
fs.copySync(paths.appPublic, paths.appBuild, {
|
||||
dereference: true,
|
||||
filter: file => file !== paths.appHtml,
|
||||
});
|
||||
}
|
117
scripts/start.js
Normal file
117
scripts/start.js
Normal file
@ -0,0 +1,117 @@
|
||||
'use strict';
|
||||
|
||||
// Do this as the first thing so that any code reading it knows the right env.
|
||||
process.env.BABEL_ENV = 'development';
|
||||
process.env.NODE_ENV = 'development';
|
||||
|
||||
// Makes the script crash on unhandled rejections instead of silently
|
||||
// ignoring them. In the future, promise rejections that are not handled will
|
||||
// terminate the Node.js process with a non-zero exit code.
|
||||
process.on('unhandledRejection', err => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
// Ensure environment variables are read.
|
||||
require('../config/env');
|
||||
|
||||
const fs = require('fs');
|
||||
const chalk = require('chalk');
|
||||
const webpack = require('webpack');
|
||||
const WebpackDevServer = require('webpack-dev-server');
|
||||
const clearConsole = require('react-dev-utils/clearConsole');
|
||||
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
||||
const {
|
||||
choosePort,
|
||||
createCompiler,
|
||||
prepareProxy,
|
||||
prepareUrls,
|
||||
} = require('react-dev-utils/WebpackDevServerUtils');
|
||||
const openBrowser = require('react-dev-utils/openBrowser');
|
||||
const paths = require('../config/paths');
|
||||
const config = require('../config/webpack.config.dev');
|
||||
const createDevServerConfig = require('../config/webpackDevServer.config');
|
||||
const startRekitStudio = require('./startRekitStudio');
|
||||
|
||||
const useYarn = fs.existsSync(paths.yarnLockFile);
|
||||
process.stdout.isTTY = false;
|
||||
const isInteractive = process.stdout.isTTY;
|
||||
|
||||
// Warn and crash if required files are missing
|
||||
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Tools like Cloud9 rely on this.
|
||||
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || require(paths.appPackageJson).rekit.devPort || 3000;
|
||||
const HOST = process.env.HOST || '0.0.0.0';
|
||||
|
||||
if (process.env.HOST) {
|
||||
console.log(
|
||||
chalk.cyan(
|
||||
`Attempting to bind to HOST environment variable: ${chalk.yellow(
|
||||
chalk.bold(process.env.HOST)
|
||||
)}`
|
||||
)
|
||||
);
|
||||
console.log(
|
||||
`If this was unintentional, check that you haven't mistakenly set it in your shell.`
|
||||
);
|
||||
console.log(`Learn more here: ${chalk.yellow('http://bit.ly/2mwWSwH')}`);
|
||||
console.log();
|
||||
}
|
||||
|
||||
// Start Rekit Studio
|
||||
const studioPort = require(paths.appPackageJson).rekit.studioPort;
|
||||
startRekitStudio(studioPort).then(() =>
|
||||
// We attempt to use the default port but if it is busy, we offer the user to
|
||||
// run on a different port. `choosePort()` Promise resolves to the next free port.
|
||||
choosePort(HOST, DEFAULT_PORT)
|
||||
.then(port => {
|
||||
if (port == null) {
|
||||
// We have not found a port.
|
||||
return;
|
||||
}
|
||||
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
||||
const appName = require(paths.appPackageJson).name;
|
||||
const urls = prepareUrls(protocol, HOST, port);
|
||||
// Create a webpack compiler that is configured with custom messages.
|
||||
const compiler = createCompiler(webpack, config, appName, urls, useYarn);
|
||||
compiler.plugin('done', stats => {
|
||||
console.log(chalk.bold(`To use Rekit Studio, access: http://localhost:${studioPort}`));
|
||||
console.log();
|
||||
});
|
||||
// Load proxy config
|
||||
const proxySetting = require(paths.appPackageJson).proxy;
|
||||
const proxyConfig = prepareProxy(proxySetting, paths.appPublic);
|
||||
// Serve webpack assets generated by the compiler over a web sever.
|
||||
const serverConfig = createDevServerConfig(
|
||||
proxyConfig,
|
||||
urls.lanUrlForConfig
|
||||
);
|
||||
const devServer = new WebpackDevServer(compiler, serverConfig);
|
||||
// Launch WebpackDevServer.
|
||||
devServer.listen(port, HOST, err => {
|
||||
if (err) {
|
||||
return console.log(err);
|
||||
}
|
||||
if (isInteractive) {
|
||||
clearConsole();
|
||||
}
|
||||
console.log(chalk.cyan('Starting the development server...\n'));
|
||||
openBrowser(urls.localUrlForBrowser);
|
||||
});
|
||||
|
||||
['SIGINT', 'SIGTERM'].forEach(function(sig) {
|
||||
process.on(sig, function() {
|
||||
devServer.close();
|
||||
process.exit();
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
if (err && err.message) {
|
||||
console.log(err.message);
|
||||
}
|
||||
process.exit(1);
|
||||
})
|
||||
);
|
38
scripts/startRekitStudio.js
Normal file
38
scripts/startRekitStudio.js
Normal file
@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
// Start Rekit Studio
|
||||
const path = require('path');
|
||||
const http = require('http');
|
||||
const express = require('express');
|
||||
const rekitStudioMiddleWare = require('rekit-studio/middleware');
|
||||
const fallback = require('express-history-api-fallback');
|
||||
|
||||
function startRekitStudio(port) {
|
||||
console.log('Starting Rekit Studio...');
|
||||
return new Promise((resolve, reject) => {
|
||||
const app = express();
|
||||
const server = http.createServer(app);
|
||||
const root = path.join(__dirname, '../node_modules/rekit-studio/dist');
|
||||
app.use(rekitStudioMiddleWare()(server, app));
|
||||
app.use(express.static(root));
|
||||
app.use(fallback('index.html', { root }));
|
||||
|
||||
// Other files should not happen, respond 404
|
||||
app.get('*', (req, res) => {
|
||||
console.log('Warning: unknown req: ', req.path);
|
||||
res.sendStatus(404);
|
||||
});
|
||||
|
||||
server.listen(port, err => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
console.log(`Rekit Studio is running at http://localhost:${port}/`);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = startRekitStudio;
|
26
scripts/test.js
Normal file
26
scripts/test.js
Normal file
@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
// Do this as the first thing so that any code reading it knows the right env.
|
||||
process.env.BABEL_ENV = 'test';
|
||||
process.env.NODE_ENV = 'test';
|
||||
process.env.PUBLIC_URL = '';
|
||||
|
||||
// Makes the script crash on unhandled rejections instead of silently
|
||||
// ignoring them. In the future, promise rejections that are not handled will
|
||||
// terminate the Node.js process with a non-zero exit code.
|
||||
process.on('unhandledRejection', err => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
// Ensure environment variables are read.
|
||||
require('../config/env');
|
||||
|
||||
const jest = require('jest');
|
||||
const argv = process.argv.slice(2);
|
||||
|
||||
// Watch unless on CI or in coverage mode
|
||||
if (!process.env.CI && argv.indexOf('--coverage') < 0 && argv.indexOf('--no-watch') < 0) {
|
||||
argv.push('--watch');
|
||||
}
|
||||
|
||||
jest.run(argv);
|
57
src/Root.js
Normal file
57
src/Root.js
Normal file
@ -0,0 +1,57 @@
|
||||
/* This is the Root component mainly initializes Redux and React Router. */
|
||||
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Provider } from 'react-redux';
|
||||
import { Switch, Route } from 'react-router-dom';
|
||||
import { ConnectedRouter } from 'react-router-redux';
|
||||
import history from './common/history';
|
||||
|
||||
function renderRouteConfigV3(routes, contextPath) {
|
||||
// Resolve route config object in React Router v3.
|
||||
const children = []; // children component list
|
||||
|
||||
const renderRoute = (item, routeContextPath) => {
|
||||
let newContextPath;
|
||||
if (/^\//.test(item.path)) {
|
||||
newContextPath = item.path;
|
||||
} else {
|
||||
newContextPath = `${routeContextPath}/${item.path}`;
|
||||
}
|
||||
newContextPath = newContextPath.replace(/\/+/g, '/');
|
||||
if (item.component && item.childRoutes) {
|
||||
const childRoutes = renderRouteConfigV3(item.childRoutes, newContextPath);
|
||||
children.push(
|
||||
<Route
|
||||
key={newContextPath}
|
||||
render={props => <item.component {...props}>{childRoutes}</item.component>}
|
||||
path={newContextPath}
|
||||
/>
|
||||
);
|
||||
} else if (item.component) {
|
||||
children.push(<Route key={newContextPath} component={item.component} path={newContextPath} exact />);
|
||||
} else if (item.childRoutes) {
|
||||
item.childRoutes.forEach(r => renderRoute(r, newContextPath));
|
||||
}
|
||||
};
|
||||
|
||||
routes.forEach(item => renderRoute(item, contextPath));
|
||||
|
||||
// Use Switch so that only the first matched route is rendered.
|
||||
return <Switch>{children}</Switch>;
|
||||
}
|
||||
|
||||
export default class Root extends React.Component {
|
||||
static propTypes = {
|
||||
store: PropTypes.object.isRequired,
|
||||
routeConfig: PropTypes.array.isRequired,
|
||||
};
|
||||
render() {
|
||||
const children = renderRouteConfigV3(this.props.routeConfig, '/');
|
||||
return (
|
||||
<Provider store={this.props.store}>
|
||||
<ConnectedRouter history={history}>{children}</ConnectedRouter>
|
||||
</Provider>
|
||||
);
|
||||
}
|
||||
}
|
44
src/common/configStore.js
Normal file
44
src/common/configStore.js
Normal file
@ -0,0 +1,44 @@
|
||||
import { createStore, applyMiddleware, compose } from 'redux';
|
||||
import thunk from 'redux-thunk';
|
||||
import { routerMiddleware } from 'react-router-redux';
|
||||
import history from './history';
|
||||
import rootReducer from './rootReducer';
|
||||
|
||||
const router = routerMiddleware(history);
|
||||
|
||||
// NOTE: Do not change middleares delaration pattern since rekit plugins may register middlewares to it.
|
||||
const middlewares = [
|
||||
thunk,
|
||||
router,
|
||||
];
|
||||
|
||||
let devToolsExtension = f => f;
|
||||
|
||||
/* istanbul ignore if */
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
const { createLogger } = require('redux-logger');
|
||||
|
||||
const logger = createLogger({ collapsed: true });
|
||||
middlewares.push(logger);
|
||||
|
||||
if (window.devToolsExtension) {
|
||||
devToolsExtension = window.devToolsExtension();
|
||||
}
|
||||
}
|
||||
|
||||
export default function configureStore(initialState) {
|
||||
const store = createStore(rootReducer, initialState, compose(
|
||||
applyMiddleware(...middlewares),
|
||||
devToolsExtension
|
||||
));
|
||||
|
||||
/* istanbul ignore if */
|
||||
if (module.hot) {
|
||||
// Enable Webpack hot module replacement for reducers
|
||||
module.hot.accept('./rootReducer', () => {
|
||||
const nextRootReducer = require('./rootReducer').default; // eslint-disable-line
|
||||
store.replaceReducer(nextRootReducer);
|
||||
});
|
||||
}
|
||||
return store;
|
||||
}
|
5
src/common/history.js
Normal file
5
src/common/history.js
Normal file
@ -0,0 +1,5 @@
|
||||
import createHistory from 'history/createBrowserHistory';
|
||||
|
||||
// A singleton history object for easy API navigation
|
||||
const history = createHistory();
|
||||
export default history;
|
19
src/common/rootReducer.js
Normal file
19
src/common/rootReducer.js
Normal file
@ -0,0 +1,19 @@
|
||||
import { combineReducers } from 'redux';
|
||||
import { routerReducer } from 'react-router-redux';
|
||||
import homeReducer from '../features/home/redux/reducer';
|
||||
import commonReducer from '../features/common/redux/reducer';
|
||||
import examplesReducer from '../features/examples/redux/reducer';
|
||||
|
||||
// NOTE 1: DO NOT CHANGE the 'reducerMap' name and the declaration pattern.
|
||||
// This is used for Rekit cmds to register new features, remove features, etc.
|
||||
// NOTE 2: always use the camel case of the feature folder name as the store branch name
|
||||
// So that it's easy for others to understand it and Rekit could manage them.
|
||||
|
||||
const reducerMap = {
|
||||
router: routerReducer,
|
||||
home: homeReducer,
|
||||
common: commonReducer,
|
||||
examples: examplesReducer,
|
||||
};
|
||||
|
||||
export default combineReducers(reducerMap);
|
44
src/common/routeConfig.js
Normal file
44
src/common/routeConfig.js
Normal file
@ -0,0 +1,44 @@
|
||||
import { App } from '../features/home';
|
||||
import { PageNotFound } from '../features/common';
|
||||
import homeRoute from '../features/home/route';
|
||||
import commonRoute from '../features/common/route';
|
||||
import examplesRoute from '../features/examples/route';
|
||||
import _ from 'lodash';
|
||||
|
||||
// NOTE: DO NOT CHANGE the 'childRoutes' name and the declaration pattern.
|
||||
// This is used for Rekit cmds to register routes config for new features, and remove config when remove features, etc.
|
||||
const childRoutes = [
|
||||
homeRoute,
|
||||
commonRoute,
|
||||
examplesRoute,
|
||||
];
|
||||
|
||||
const routes = [{
|
||||
path: '/',
|
||||
component: App,
|
||||
childRoutes: [
|
||||
...childRoutes,
|
||||
{ path: '*', name: 'Page not found', component: PageNotFound },
|
||||
].filter(r => r.component || (r.childRoutes && r.childRoutes.length > 0)),
|
||||
}];
|
||||
|
||||
// Handle isIndex property of route config:
|
||||
// Dupicate it and put it as the first route rule.
|
||||
function handleIndexRoute(route) {
|
||||
if (!route.childRoutes || !route.childRoutes.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const indexRoute = _.find(route.childRoutes, (child => child.isIndex));
|
||||
if (indexRoute) {
|
||||
const first = { ...indexRoute };
|
||||
first.path = '';
|
||||
first.exact = true;
|
||||
first.autoIndexRoute = true; // mark it so that the simple nav won't show it.
|
||||
route.childRoutes.unshift(first);
|
||||
}
|
||||
route.childRoutes.forEach(handleIndexRoute);
|
||||
}
|
||||
|
||||
routes.forEach(handleIndexRoute);
|
||||
export default routes;
|
BIN
src/favicon.png
Normal file
BIN
src/favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
11
src/features/common/PageNotFound.js
Normal file
11
src/features/common/PageNotFound.js
Normal file
@ -0,0 +1,11 @@
|
||||
import React, { PureComponent } from 'react';
|
||||
|
||||
export default class PageNotFound extends PureComponent {
|
||||
render() {
|
||||
return (
|
||||
<div className="common-page-not-found">
|
||||
Page not found.
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
5
src/features/common/PageNotFound.scss
Normal file
5
src/features/common/PageNotFound.scss
Normal file
@ -0,0 +1,5 @@
|
||||
@import '../../styles/mixins';
|
||||
|
||||
.common-page-not-found {
|
||||
color: red;
|
||||
}
|
1
src/features/common/index.js
Normal file
1
src/features/common/index.js
Normal file
@ -0,0 +1 @@
|
||||
export { default as PageNotFound } from './PageNotFound';
|
0
src/features/common/redux/actions.js
Normal file
0
src/features/common/redux/actions.js
Normal file
0
src/features/common/redux/constants.js
Normal file
0
src/features/common/redux/constants.js
Normal file
12
src/features/common/redux/initialState.js
Normal file
12
src/features/common/redux/initialState.js
Normal file
@ -0,0 +1,12 @@
|
||||
// Initial state is the place you define all initial values for the Redux store of the feature.
|
||||
// In the 'standard' way, initialState is defined in reducers: http://redux.js.org/docs/basics/Reducers.html
|
||||
// But when application grows, there will be multiple reducers files, it's not intuitive what data is managed by the whole store.
|
||||
// So Rekit extracts the initial state definition into a separate module so that you can have
|
||||
// a quick view about what data is used for the feature, at any time.
|
||||
|
||||
// NOTE: initialState constant is necessary so that Rekit could auto add initial state when creating async actions.
|
||||
|
||||
const initialState = {
|
||||
};
|
||||
|
||||
export default initialState;
|
24
src/features/common/redux/reducer.js
Normal file
24
src/features/common/redux/reducer.js
Normal file
@ -0,0 +1,24 @@
|
||||
// This is the root reducer of the feature. It is used for:
|
||||
// 1. Load reducers from each action in the feature and process them one by one.
|
||||
// Note that this part of code is mainly maintained by Rekit, you usually don't need to edit them.
|
||||
// 2. Write cross-topic reducers. If a reducer is not bound to some specific action.
|
||||
// Then it could be written here.
|
||||
// Learn more from the introduction of this approach:
|
||||
// https://medium.com/@nate_wang/a-new-approach-for-managing-redux-actions-91c26ce8b5da.
|
||||
|
||||
import initialState from './initialState';
|
||||
|
||||
const reducers = [
|
||||
];
|
||||
|
||||
export default function reducer(state = initialState, action) {
|
||||
let newState;
|
||||
switch (action.type) {
|
||||
// Handle cross-topic actions here
|
||||
default:
|
||||
newState = state;
|
||||
break;
|
||||
}
|
||||
/* istanbul ignore next */
|
||||
return reducers.reduce((s, r) => r(s, action), newState);
|
||||
}
|
9
src/features/common/route.js
Normal file
9
src/features/common/route.js
Normal file
@ -0,0 +1,9 @@
|
||||
// This is the JSON way to define React Router rules in a Rekit app.
|
||||
// Learn more from: http://rekit.js.org/docs/routing.html
|
||||
|
||||
export default {
|
||||
path: 'common',
|
||||
name: 'Common',
|
||||
childRoutes: [
|
||||
],
|
||||
};
|
1
src/features/common/style.scss
Normal file
1
src/features/common/style.scss
Normal file
@ -0,0 +1 @@
|
||||
@import '../../styles/mixins';
|
45
src/features/examples/CounterPage.js
Normal file
45
src/features/examples/CounterPage.js
Normal file
@ -0,0 +1,45 @@
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { connect } from 'react-redux';
|
||||
import * as actions from './redux/actions';
|
||||
|
||||
export class CounterPage extends Component {
|
||||
static propTypes = {
|
||||
examples: PropTypes.object.isRequired,
|
||||
actions: PropTypes.object.isRequired,
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="examples-counter-page">
|
||||
<h1>Counter</h1>
|
||||
<p>This is simple counter demo to show how Redux sync actions work.</p>
|
||||
<button className="btn-minus-one" onClick={this.props.actions.counterMinusOne} disabled={this.props.examples.count === 0}>
|
||||
-
|
||||
</button>
|
||||
<span>{this.props.examples.count}</span>
|
||||
<button className="btn-plus-one" onClick={this.props.actions.counterPlusOne}>+</button>
|
||||
<button className="btn-reset" onClick={this.props.actions.counterReset}>
|
||||
Reset
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
examples: state.examples,
|
||||
};
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
actions: bindActionCreators({ ...actions }, dispatch),
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(CounterPage);
|
18
src/features/examples/CounterPage.scss
Normal file
18
src/features/examples/CounterPage.scss
Normal file
@ -0,0 +1,18 @@
|
||||
@import '../../styles/mixins';
|
||||
|
||||
.examples-counter-page {
|
||||
color: #555;
|
||||
h1 {
|
||||
margin-top: 0px;
|
||||
font-size: 28px;
|
||||
}
|
||||
span {
|
||||
padding: 0 10px;
|
||||
display: inline-block;
|
||||
min-width: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
button.btn-reset {
|
||||
margin-left: 15px;
|
||||
}
|
||||
}
|
20
src/features/examples/Layout.js
Normal file
20
src/features/examples/Layout.js
Normal file
@ -0,0 +1,20 @@
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { SidePanel } from './';
|
||||
|
||||
export default class Layout extends Component {
|
||||
static propTypes = {
|
||||
children: PropTypes.node,
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="examples-layout">
|
||||
<SidePanel />
|
||||
<div className="examples-page-container">
|
||||
{this.props.children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
9
src/features/examples/Layout.scss
Normal file
9
src/features/examples/Layout.scss
Normal file
@ -0,0 +1,9 @@
|
||||
@import '../../styles/mixins';
|
||||
|
||||
.examples-layout {
|
||||
.examples-page-container {
|
||||
padding: 40px 30px 0 300px;
|
||||
min-width: 400px;
|
||||
max-width: 800px;
|
||||
}
|
||||
}
|
57
src/features/examples/RedditListPage.js
Normal file
57
src/features/examples/RedditListPage.js
Normal file
@ -0,0 +1,57 @@
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { connect } from 'react-redux';
|
||||
import { fetchRedditList } from './redux/actions';
|
||||
|
||||
export class RedditListPage extends Component {
|
||||
static propTypes = {
|
||||
examples: PropTypes.object.isRequired,
|
||||
actions: PropTypes.object.isRequired,
|
||||
};
|
||||
|
||||
render() {
|
||||
const { fetchRedditListPending, redditList, fetchRedditListError } = this.props.examples;
|
||||
const { fetchRedditList } = this.props.actions;
|
||||
|
||||
return (
|
||||
<div className="examples-reddit-list-page">
|
||||
<h1>Reddit API Usage</h1>
|
||||
<p>This demo shows how to use Redux async actions to fetch data from Reddit's REST API.</p>
|
||||
<button className="btn-fetch-reddit" disabled={fetchRedditListPending} onClick={fetchRedditList}>
|
||||
{fetchRedditListPending ? 'Fetching...' : 'Fetch reactjs topics'}
|
||||
</button>
|
||||
{fetchRedditListError && (
|
||||
<div className="fetch-list-error">Failed to load: {fetchRedditListError.toString()}</div>
|
||||
)}
|
||||
{redditList.length > 0 ? (
|
||||
<ul className="examples-reddit-list">
|
||||
{redditList.map(item => (
|
||||
<li key={item.data.id}>
|
||||
<a href={item.data.url}>{item.data.title}</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<div className="no-items-tip">No items yet.</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
examples: state.examples,
|
||||
};
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
actions: bindActionCreators({ fetchRedditList }, dispatch),
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(RedditListPage);
|
24
src/features/examples/RedditListPage.scss
Normal file
24
src/features/examples/RedditListPage.scss
Normal file
@ -0,0 +1,24 @@
|
||||
@import '../../styles/mixins';
|
||||
|
||||
.examples-reddit-list-page {
|
||||
color: #555;
|
||||
h1 {
|
||||
margin-top: 0px;
|
||||
font-size: 28px;
|
||||
}
|
||||
a {
|
||||
color: #2db7f5;
|
||||
text-decoration: none;
|
||||
&:hover {
|
||||
color: #f90;
|
||||
}
|
||||
}
|
||||
.fetch-list-error {
|
||||
display: block;
|
||||
margin-top: 20px;
|
||||
color: red;
|
||||
}
|
||||
.no-items-tip {
|
||||
margin-top: 15px;
|
||||
}
|
||||
}
|
54
src/features/examples/SidePanel.js
Normal file
54
src/features/examples/SidePanel.js
Normal file
@ -0,0 +1,54 @@
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { connect } from 'react-redux';
|
||||
import * as actions from './redux/actions';
|
||||
|
||||
export class SidePanel extends Component {
|
||||
static propTypes = {
|
||||
examples: PropTypes.object.isRequired,
|
||||
actions: PropTypes.object.isRequired,
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="examples-side-panel">
|
||||
<ul>
|
||||
<li>
|
||||
<Link to="/examples">Welcome</Link>
|
||||
</li>
|
||||
<li>
|
||||
<Link to="/examples/counter">Counter Demo</Link>
|
||||
</li>
|
||||
<li>
|
||||
<Link to="/examples/reddit">Reddit API Demo</Link>
|
||||
</li>
|
||||
<li>
|
||||
<Link to="/">Back to start page</Link>
|
||||
</li>
|
||||
</ul>
|
||||
<div className="memo">
|
||||
This is a Rekit feature that contains some examples for you to quick learn how Rekit works. To remove it just
|
||||
delete the feature.
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
examples: state.examples,
|
||||
};
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
actions: bindActionCreators({ ...actions }, dispatch),
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(SidePanel);
|
46
src/features/examples/SidePanel.scss
Normal file
46
src/features/examples/SidePanel.scss
Normal file
@ -0,0 +1,46 @@
|
||||
@import '../../styles/mixins';
|
||||
|
||||
.examples-side-panel {
|
||||
position: fixed;
|
||||
box-sizing: border-box;
|
||||
overflow: auto;
|
||||
top: 0;
|
||||
left: 0;
|
||||
margin: 0;
|
||||
padding: 40px;
|
||||
width: 260px;
|
||||
height: 100%;
|
||||
background-color: #f7f7f7;
|
||||
ul,
|
||||
li {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
list-style: none;
|
||||
}
|
||||
li {
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #2db7f5;
|
||||
text-decoration: none;
|
||||
&:hover {
|
||||
color: #f90;
|
||||
}
|
||||
}
|
||||
|
||||
.memo {
|
||||
&:before {
|
||||
content: ' ';
|
||||
display: block;
|
||||
height: 2px;
|
||||
width: 60px;
|
||||
margin-bottom: 10px;
|
||||
background-color: #ddd;
|
||||
}
|
||||
font-size: 13px;
|
||||
margin-top: 40px;
|
||||
line-height: 150%;
|
||||
color: #aaa;
|
||||
}
|
||||
}
|
57
src/features/examples/WelcomePage.js
Normal file
57
src/features/examples/WelcomePage.js
Normal file
@ -0,0 +1,57 @@
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { connect } from 'react-redux';
|
||||
import rekitLogo from '../../images/rekit-logo.svg';
|
||||
import * as actions from './redux/actions';
|
||||
|
||||
export class WelcomePage extends Component {
|
||||
static propTypes = {
|
||||
examples: PropTypes.object.isRequired,
|
||||
actions: PropTypes.object.isRequired,
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="examples-welcome-page">
|
||||
<a href="http://github.com/supnate/rekit">
|
||||
<img src={rekitLogo} className="app-logo" alt="logo" />
|
||||
</a>
|
||||
<h1>Welcome to Rekit!</h1>
|
||||
<p>
|
||||
Contratulations! You have created your Rekit app successfully! Seeing this page means everything works well
|
||||
now.
|
||||
</p>
|
||||
<p>
|
||||
By default <a href="https://github.com/supnate/rekit">Rekit Studio</a> is also started at{' '}
|
||||
<a href="http://localhost:6076">http://localhost:6076</a> to manage the project.
|
||||
</p>
|
||||
<p>
|
||||
This is an example feature showing about how to layout the container, how to use Redux and React Router. If
|
||||
you want to remove all sample code, just delete the feature from Rekit Studio. Alternatively you can run
|
||||
<code>rekit remove feature examples</code> by command line under the project folder.
|
||||
</p>
|
||||
<p>
|
||||
To learn more about how to get started, you can visit:{' '}
|
||||
<a href="http://rekit.js.org/docs/get-started.html">Get started</a>
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
examples: state.examples,
|
||||
};
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
actions: bindActionCreators({ ...actions }, dispatch),
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(WelcomePage);
|
36
src/features/examples/WelcomePage.scss
Normal file
36
src/features/examples/WelcomePage.scss
Normal file
@ -0,0 +1,36 @@
|
||||
@import '../../styles/mixins';
|
||||
|
||||
.examples-welcome-page {
|
||||
line-height: 160%;
|
||||
position: relative;
|
||||
color: #555;
|
||||
|
||||
a {
|
||||
color: #2db7f5;
|
||||
text-decoration: none;
|
||||
&:hover {
|
||||
color: #f90;
|
||||
}
|
||||
}
|
||||
|
||||
.app-logo {
|
||||
position: absolute;
|
||||
top: -14px;
|
||||
left: 0px;
|
||||
width: 50px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
padding-left: 60px;
|
||||
margin-bottom: 40px;
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
h3 {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
code {
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
5
src/features/examples/index.js
Normal file
5
src/features/examples/index.js
Normal file
@ -0,0 +1,5 @@
|
||||
export { default as SidePanel } from './SidePanel';
|
||||
export { default as WelcomePage } from './WelcomePage';
|
||||
export { default as CounterPage } from './CounterPage';
|
||||
export { default as RedditListPage } from './RedditListPage';
|
||||
export { default as Layout } from './Layout';
|
4
src/features/examples/redux/actions.js
Normal file
4
src/features/examples/redux/actions.js
Normal file
@ -0,0 +1,4 @@
|
||||
export { counterPlusOne } from './counterPlusOne';
|
||||
export { counterMinusOne } from './counterMinusOne';
|
||||
export { counterReset } from './counterReset';
|
||||
export { fetchRedditList, dismissFetchRedditListError } from './fetchRedditList';
|
7
src/features/examples/redux/constants.js
Normal file
7
src/features/examples/redux/constants.js
Normal file
@ -0,0 +1,7 @@
|
||||
export const EXAMPLES_COUNTER_PLUS_ONE = 'EXAMPLES_COUNTER_PLUS_ONE';
|
||||
export const EXAMPLES_COUNTER_MINUS_ONE = 'EXAMPLES_COUNTER_MINUS_ONE';
|
||||
export const EXAMPLES_COUNTER_RESET = 'EXAMPLES_COUNTER_RESET';
|
||||
export const EXAMPLES_FETCH_REDDIT_LIST_BEGIN = 'EXAMPLES_FETCH_REDDIT_LIST_BEGIN';
|
||||
export const EXAMPLES_FETCH_REDDIT_LIST_SUCCESS = 'EXAMPLES_FETCH_REDDIT_LIST_SUCCESS';
|
||||
export const EXAMPLES_FETCH_REDDIT_LIST_FAILURE = 'EXAMPLES_FETCH_REDDIT_LIST_FAILURE';
|
||||
export const EXAMPLES_FETCH_REDDIT_LIST_DISMISS_ERROR = 'EXAMPLES_FETCH_REDDIT_LIST_DISMISS_ERROR';
|
24
src/features/examples/redux/counterMinusOne.js
Normal file
24
src/features/examples/redux/counterMinusOne.js
Normal file
@ -0,0 +1,24 @@
|
||||
// Rekit uses a new approach to organizing actions and reducers. That is
|
||||
// putting related actions and reducers in one file. See more at:
|
||||
// https://medium.com/@nate_wang/a-new-approach-for-managing-redux-actions-91c26ce8b5da
|
||||
|
||||
import { EXAMPLES_COUNTER_MINUS_ONE } from './constants';
|
||||
|
||||
export function counterMinusOne() {
|
||||
return {
|
||||
type: EXAMPLES_COUNTER_MINUS_ONE,
|
||||
};
|
||||
}
|
||||
|
||||
export function reducer(state, action) {
|
||||
switch (action.type) {
|
||||
case EXAMPLES_COUNTER_MINUS_ONE:
|
||||
return {
|
||||
...state,
|
||||
count: state.count - 1,
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
24
src/features/examples/redux/counterPlusOne.js
Normal file
24
src/features/examples/redux/counterPlusOne.js
Normal file
@ -0,0 +1,24 @@
|
||||
// Rekit uses a new approach to organizing actions and reducers. That is
|
||||
// putting related actions and reducers in one file. See more at:
|
||||
// https://medium.com/@nate_wang/a-new-approach-for-managing-redux-actions-91c26ce8b5da
|
||||
|
||||
import { EXAMPLES_COUNTER_PLUS_ONE } from './constants';
|
||||
|
||||
export function counterPlusOne() {
|
||||
return {
|
||||
type: EXAMPLES_COUNTER_PLUS_ONE,
|
||||
};
|
||||
}
|
||||
|
||||
export function reducer(state, action) {
|
||||
switch (action.type) {
|
||||
case EXAMPLES_COUNTER_PLUS_ONE:
|
||||
return {
|
||||
...state,
|
||||
count: state.count + 1,
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
24
src/features/examples/redux/counterReset.js
Normal file
24
src/features/examples/redux/counterReset.js
Normal file
@ -0,0 +1,24 @@
|
||||
// Rekit uses a new approach to organizing actions and reducers. That is
|
||||
// putting related actions and reducers in one file. See more at:
|
||||
// https://medium.com/@nate_wang/a-new-approach-for-managing-redux-actions-91c26ce8b5da
|
||||
|
||||
import { EXAMPLES_COUNTER_RESET } from './constants';
|
||||
|
||||
export function counterReset() {
|
||||
return {
|
||||
type: EXAMPLES_COUNTER_RESET,
|
||||
};
|
||||
}
|
||||
|
||||
export function reducer(state, action) {
|
||||
switch (action.type) {
|
||||
case EXAMPLES_COUNTER_RESET:
|
||||
return {
|
||||
...state,
|
||||
count: 0,
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
97
src/features/examples/redux/fetchRedditList.js
Normal file
97
src/features/examples/redux/fetchRedditList.js
Normal file
@ -0,0 +1,97 @@
|
||||
import axios from 'axios';
|
||||
import {
|
||||
EXAMPLES_FETCH_REDDIT_LIST_BEGIN,
|
||||
EXAMPLES_FETCH_REDDIT_LIST_SUCCESS,
|
||||
EXAMPLES_FETCH_REDDIT_LIST_FAILURE,
|
||||
EXAMPLES_FETCH_REDDIT_LIST_DISMISS_ERROR,
|
||||
} from './constants';
|
||||
|
||||
// Rekit uses redux-thunk for async actions by default: https://github.com/gaearon/redux-thunk
|
||||
// If you prefer redux-saga, you can use rekit-plugin-redux-saga: https://github.com/supnate/rekit-plugin-redux-saga
|
||||
export function fetchRedditList(args = {}) {
|
||||
return dispatch => {
|
||||
// optionally you can have getState as the second argument
|
||||
dispatch({
|
||||
type: EXAMPLES_FETCH_REDDIT_LIST_BEGIN,
|
||||
});
|
||||
|
||||
// Return a promise so that you could control UI flow without states in the store.
|
||||
// For example: after submit a form, you need to redirect the page to another when succeeds or show some errors message if fails.
|
||||
// It's hard to use state to manage it, but returning a promise allows you to easily achieve it.
|
||||
// e.g.: handleSubmit() { this.props.actions.submitForm(data).then(()=> {}).catch(() => {}); }
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
// doRequest is a placeholder Promise. You should replace it with your own logic.
|
||||
// See the real-word example at: https://github.com/supnate/rekit/blob/master/src/features/home/redux/fetchRedditReactjsList.js
|
||||
// args.error here is only for test coverage purpose.
|
||||
const doRequest = axios.get('http://www.reddit.com/r/reactjs.json');
|
||||
|
||||
doRequest.then(
|
||||
res => {
|
||||
dispatch({
|
||||
type: EXAMPLES_FETCH_REDDIT_LIST_SUCCESS,
|
||||
data: res.data,
|
||||
});
|
||||
resolve(res);
|
||||
},
|
||||
// Use rejectHandler as the second argument so that render errors won't be caught.
|
||||
err => {
|
||||
dispatch({
|
||||
type: EXAMPLES_FETCH_REDDIT_LIST_FAILURE,
|
||||
data: { error: err },
|
||||
});
|
||||
reject(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
return promise;
|
||||
};
|
||||
}
|
||||
|
||||
// Async action saves request error by default, this method is used to dismiss the error info.
|
||||
// If you don't want errors to be saved in Redux store, just ignore this method.
|
||||
export function dismissFetchRedditListError() {
|
||||
return {
|
||||
type: EXAMPLES_FETCH_REDDIT_LIST_DISMISS_ERROR,
|
||||
};
|
||||
}
|
||||
|
||||
export function reducer(state, action) {
|
||||
switch (action.type) {
|
||||
case EXAMPLES_FETCH_REDDIT_LIST_BEGIN:
|
||||
// Just after a request is sent
|
||||
return {
|
||||
...state,
|
||||
fetchRedditListPending: true,
|
||||
fetchRedditListError: null,
|
||||
};
|
||||
|
||||
case EXAMPLES_FETCH_REDDIT_LIST_SUCCESS:
|
||||
// The request is success
|
||||
return {
|
||||
...state,
|
||||
redditList: action.data.data.children,
|
||||
|
||||
fetchRedditListPending: false,
|
||||
fetchRedditListError: null,
|
||||
};
|
||||
|
||||
case EXAMPLES_FETCH_REDDIT_LIST_FAILURE:
|
||||
// The request is failed
|
||||
return {
|
||||
...state,
|
||||
fetchRedditListPending: false,
|
||||
fetchRedditListError: action.data.error,
|
||||
};
|
||||
|
||||
case EXAMPLES_FETCH_REDDIT_LIST_DISMISS_ERROR:
|
||||
// Dismiss the request failure error
|
||||
return {
|
||||
...state,
|
||||
fetchRedditListError: null,
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
15
src/features/examples/redux/initialState.js
Normal file
15
src/features/examples/redux/initialState.js
Normal file
@ -0,0 +1,15 @@
|
||||
// Initial state is the place you define all initial values for the Redux store of the feature.
|
||||
// In the 'standard' way, initialState is defined in reducers: http://redux.js.org/docs/basics/Reducers.html
|
||||
// But when application grows, there will be multiple reducers files, it's not intuitive what data is managed by the whole store.
|
||||
// So Rekit extracts the initial state definition into a separate module so that you can have
|
||||
// a quick view about what data is used for the feature, at any time.
|
||||
|
||||
// NOTE: initialState constant is necessary so that Rekit could auto add initial state when creating async actions.
|
||||
const initialState = {
|
||||
count: 0,
|
||||
redditList: [],
|
||||
fetchRedditListPending: false,
|
||||
fetchRedditListError: null,
|
||||
};
|
||||
|
||||
export default initialState;
|
31
src/features/examples/redux/reducer.js
Normal file
31
src/features/examples/redux/reducer.js
Normal file
@ -0,0 +1,31 @@
|
||||
// This is the root reducer of the feature. It is used for:
|
||||
// 1. Load reducers from each action in the feature and process them one by one.
|
||||
// Note that this part of code is mainly maintained by Rekit, you usually don't need to edit them.
|
||||
// 2. Write cross-topic reducers. If a reducer is not bound to some specific action.
|
||||
// Then it could be written here.
|
||||
// Learn more from the introduction of this approach:
|
||||
// https://medium.com/@nate_wang/a-new-approach-for-managing-redux-actions-91c26ce8b5da.
|
||||
|
||||
import initialState from './initialState';
|
||||
import { reducer as counterPlusOneReducer } from './counterPlusOne';
|
||||
import { reducer as counterMinusOneReducer } from './counterMinusOne';
|
||||
import { reducer as counterResetReducer } from './counterReset';
|
||||
import { reducer as fetchRedditListReducer } from './fetchRedditList';
|
||||
|
||||
const reducers = [
|
||||
counterPlusOneReducer,
|
||||
counterMinusOneReducer,
|
||||
counterResetReducer,
|
||||
fetchRedditListReducer,
|
||||
];
|
||||
|
||||
export default function reducer(state = initialState, action) {
|
||||
let newState;
|
||||
switch (action.type) {
|
||||
// Handle cross-topic actions here
|
||||
default:
|
||||
newState = state;
|
||||
break;
|
||||
}
|
||||
return reducers.reduce((s, r) => r(s, action), newState);
|
||||
}
|
20
src/features/examples/route.js
Normal file
20
src/features/examples/route.js
Normal file
@ -0,0 +1,20 @@
|
||||
// This is the JSON way to define React Router rules in a Rekit app.
|
||||
// Learn more from: http://rekit.js.org/docs/routing.html
|
||||
|
||||
import {
|
||||
WelcomePage,
|
||||
CounterPage,
|
||||
RedditListPage,
|
||||
Layout,
|
||||
} from './';
|
||||
|
||||
export default {
|
||||
path: 'examples',
|
||||
name: 'Examples',
|
||||
component: Layout,
|
||||
childRoutes: [
|
||||
{ path: '', name: 'Welcome page', component: WelcomePage },
|
||||
{ path: 'counter', name: 'Counter page', component: CounterPage },
|
||||
{ path: 'reddit', name: 'Reddit list page', component: RedditListPage },
|
||||
],
|
||||
};
|
6
src/features/examples/style.scss
Normal file
6
src/features/examples/style.scss
Normal file
@ -0,0 +1,6 @@
|
||||
@import '../../styles/mixins';
|
||||
@import './SidePanel';
|
||||
@import './WelcomePage';
|
||||
@import './CounterPage';
|
||||
@import './RedditListPage';
|
||||
@import './Layout';
|
25
src/features/home/App.js
Normal file
25
src/features/home/App.js
Normal file
@ -0,0 +1,25 @@
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
/*
|
||||
This is the root component of your app. Here you define the overall layout
|
||||
and the container of the react router.
|
||||
You should adjust it according to the requirement of your app.
|
||||
*/
|
||||
export default class App extends Component {
|
||||
static propTypes = {
|
||||
children: PropTypes.node,
|
||||
};
|
||||
|
||||
static defaultProps = {
|
||||
children: '',
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="home-app">
|
||||
<div className="page-container">{this.props.children}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
4
src/features/home/App.scss
Normal file
4
src/features/home/App.scss
Normal file
@ -0,0 +1,4 @@
|
||||
@import '../../styles/mixins';
|
||||
|
||||
.home-app {
|
||||
}
|
80
src/features/home/DefaultPage.js
Normal file
80
src/features/home/DefaultPage.js
Normal file
@ -0,0 +1,80 @@
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { connect } from 'react-redux';
|
||||
import { Link } from 'react-router-dom';
|
||||
import reactLogo from '../../images/react-logo.svg';
|
||||
import rekitLogo from '../../images/rekit-logo.svg';
|
||||
import * as actions from './redux/actions';
|
||||
|
||||
export class DefaultPage extends Component {
|
||||
static propTypes = {
|
||||
home: PropTypes.object.isRequired,
|
||||
actions: PropTypes.object.isRequired,
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="home-default-page">
|
||||
<header className="app-header">
|
||||
<img src={reactLogo} className="app-logo" alt="logo" />
|
||||
<img src={rekitLogo} className="rekit-logo" alt="logo" />
|
||||
<h1 className="app-title">Welcome to React</h1>
|
||||
</header>
|
||||
<div className="app-intro">
|
||||
<h3>To get started:</h3>
|
||||
<ul>
|
||||
<li>
|
||||
Edit component{' '}
|
||||
<a
|
||||
href="http://localhost:6076/element/src%2Ffeatures%2Fhome%2FDefaultPage.js/code"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
src/features/home/DefaultPage.js
|
||||
</a>{' '}
|
||||
for this page.
|
||||
</li>
|
||||
<li>
|
||||
Edit component{' '}
|
||||
<a
|
||||
href="http://localhost:6076/element/src%2Ffeatures%2Fhome%2FApp.js/code"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
src/features/home/App.js
|
||||
</a>{' '}
|
||||
for the root container layout.
|
||||
</li>
|
||||
<li>
|
||||
To see examples, access:
|
||||
<Link to="/examples">/examples</Link>
|
||||
</li>
|
||||
<li>
|
||||
Rekit Studio is running at:
|
||||
<a href="http://localhost:6076/" target="_blank" rel="noopener noreferrer">
|
||||
http://localhost:6076/
|
||||
</a>.
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
home: state.home,
|
||||
};
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
actions: bindActionCreators({ ...actions }, dispatch),
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(DefaultPage);
|
77
src/features/home/DefaultPage.scss
Normal file
77
src/features/home/DefaultPage.scss
Normal file
@ -0,0 +1,77 @@
|
||||
@import '../../styles/mixins';
|
||||
|
||||
.home-default-page {
|
||||
text-align: center;
|
||||
.app {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.app-logo {
|
||||
animation: app-logo-spin infinite 10s linear;
|
||||
height: 80px;
|
||||
}
|
||||
|
||||
.rekit-logo {
|
||||
position: absolute;
|
||||
left: 0px;
|
||||
top: 0px;
|
||||
opacity: 0.08;
|
||||
height: 190px;
|
||||
}
|
||||
|
||||
.app-header {
|
||||
background-color: #222;
|
||||
height: 150px;
|
||||
padding: 20px;
|
||||
color: white;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.app-title {
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
.app-intro {
|
||||
font-size: large;
|
||||
}
|
||||
|
||||
ul,
|
||||
li {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
ul {
|
||||
margin-top: 20px;
|
||||
}
|
||||
li {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #0288d1;
|
||||
text-decoration: none;
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
p.memo {
|
||||
width: 500px;
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
line-height: 150%;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
@keyframes app-logo-spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
}
|
2
src/features/home/index.js
Normal file
2
src/features/home/index.js
Normal file
@ -0,0 +1,2 @@
|
||||
export { default as App } from './App';
|
||||
export { default as DefaultPage } from './DefaultPage';
|
0
src/features/home/redux/actions.js
Normal file
0
src/features/home/redux/actions.js
Normal file
0
src/features/home/redux/constants.js
Normal file
0
src/features/home/redux/constants.js
Normal file
4
src/features/home/redux/initialState.js
Normal file
4
src/features/home/redux/initialState.js
Normal file
@ -0,0 +1,4 @@
|
||||
const initialState = {
|
||||
};
|
||||
|
||||
export default initialState;
|
16
src/features/home/redux/reducer.js
Normal file
16
src/features/home/redux/reducer.js
Normal file
@ -0,0 +1,16 @@
|
||||
import initialState from './initialState';
|
||||
|
||||
const reducers = [
|
||||
];
|
||||
|
||||
export default function reducer(state = initialState, action) {
|
||||
let newState;
|
||||
switch (action.type) {
|
||||
// Handle cross-topic actions here
|
||||
default:
|
||||
newState = state;
|
||||
break;
|
||||
}
|
||||
/* istanbul ignore next */
|
||||
return reducers.reduce((s, r) => r(s, action), newState);
|
||||
}
|
15
src/features/home/route.js
Normal file
15
src/features/home/route.js
Normal file
@ -0,0 +1,15 @@
|
||||
import {
|
||||
DefaultPage,
|
||||
} from './';
|
||||
|
||||
export default {
|
||||
path: '/',
|
||||
name: 'Home',
|
||||
childRoutes: [
|
||||
{ path: 'default-page',
|
||||
name: 'Default page',
|
||||
component: DefaultPage,
|
||||
isIndex: true,
|
||||
},
|
||||
],
|
||||
};
|
3
src/features/home/style.scss
Normal file
3
src/features/home/style.scss
Normal file
@ -0,0 +1,3 @@
|
||||
@import '../../styles/mixins';
|
||||
@import './App';
|
||||
@import './DefaultPage';
|
BIN
src/images/logo.png
Normal file
BIN
src/images/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 132 KiB |
7
src/images/react-logo.svg
Normal file
7
src/images/react-logo.svg
Normal file
@ -0,0 +1,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3">
|
||||
<g fill="#61DAFB">
|
||||
<path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/>
|
||||
<circle cx="420.9" cy="296.5" r="45.7"/>
|
||||
<path d="M520.5 78.1z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.6 KiB |
32
src/images/rekit-logo.svg
Normal file
32
src/images/rekit-logo.svg
Normal file
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="507px" height="508px" viewBox="0 0 507 508" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<!-- Generator: Sketch 43.2 (39069) - http://www.bohemiancoding.com/sketch -->
|
||||
<title>Group</title>
|
||||
<desc>Created with Sketch.</desc>
|
||||
<defs>
|
||||
<linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="linearGradient-1">
|
||||
<stop stop-color="#40C1C5" offset="0%"></stop>
|
||||
<stop stop-color="#79D8DD" offset="100%"></stop>
|
||||
</linearGradient>
|
||||
<linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="linearGradient-2">
|
||||
<stop stop-color="#A46E46" offset="0%"></stop>
|
||||
<stop stop-color="#CA8F6B" offset="100%"></stop>
|
||||
</linearGradient>
|
||||
<linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="linearGradient-3">
|
||||
<stop stop-color="#F08036" offset="0%"></stop>
|
||||
<stop stop-color="#FAA881" offset="100%"></stop>
|
||||
</linearGradient>
|
||||
<linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="linearGradient-4">
|
||||
<stop stop-color="#FBC233" offset="0%"></stop>
|
||||
<stop stop-color="#FEDB67" offset="100%"></stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="Group" transform="translate(253.321158, 254.321158) rotate(45.000000) translate(-253.321158, -254.321158) translate(2.321158, 2.821158)">
|
||||
<path d="M340.717172,467.819581 C380.254364,429.329041 441.615845,371.356861 441.615845,315.632062 C441.615845,259.907264 396.44197,214.733389 340.717172,214.733389 C284.992373,214.733389 239.818498,259.907264 239.818498,315.632062 C239.818498,371.356861 301.773607,429.329041 340.717172,467.819581 Z" id="Oval" fill="url(#linearGradient-1)" transform="translate(340.717172, 341.276485) scale(1, -1) rotate(45.000000) translate(-340.717172, -341.276485) "></path>
|
||||
<path d="M160.1003,466.687889 C199.285347,428.540172 260.1003,371.084332 260.1003,315.855857 C260.1003,260.627382 215.328775,215.855857 160.1003,215.855857 C104.871825,215.855857 60.1003,260.627382 60.1003,315.855857 C60.1003,371.084332 121.503594,428.540172 160.1003,466.687889 Z" id="Oval" fill="url(#linearGradient-2)" transform="translate(160.100300, 341.271873) scale(-1, -1) rotate(45.000000) translate(-160.100300, -341.271873) "></path>
|
||||
<path d="M340.171573,285.417818 C379.35662,247.270101 440.171573,189.814261 440.171573,134.585786 C440.171573,79.3573115 395.400048,34.5857864 340.171573,34.5857864 C284.943098,34.5857864 240.171573,79.3573115 240.171573,134.585786 C240.171573,189.814261 301.574866,247.270101 340.171573,285.417818 Z" id="Oval" fill="url(#linearGradient-3)" transform="translate(340.171573, 160.001802) rotate(45.000000) translate(-340.171573, -160.001802) "></path>
|
||||
<path d="M159.707107,286.124924 C198.892154,247.977208 259.707107,190.521368 259.707107,135.292893 C259.707107,80.0644182 214.935582,35.2928932 159.707107,35.2928932 C104.478632,35.2928932 59.7071068,80.0644182 59.7071068,135.292893 C59.7071068,190.521368 121.1104,247.977208 159.707107,286.124924 Z" id="Oval" fill="url(#linearGradient-4)" transform="translate(159.707107, 160.708909) scale(-1, 1) rotate(45.000000) translate(-159.707107, -160.708909) "></path>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 3.3 KiB |
32
src/index.js
Normal file
32
src/index.js
Normal file
@ -0,0 +1,32 @@
|
||||
import React from 'react';
|
||||
import { AppContainer } from 'react-hot-loader';
|
||||
import { render } from 'react-dom';
|
||||
import configStore from './common/configStore';
|
||||
import routeConfig from './common/routeConfig';
|
||||
import Root from './Root';
|
||||
|
||||
const store = configStore();
|
||||
|
||||
function renderApp(app) {
|
||||
render(
|
||||
<AppContainer>
|
||||
{app}
|
||||
</AppContainer>,
|
||||
document.getElementById('root')
|
||||
);
|
||||
}
|
||||
|
||||
renderApp(<Root store={store} routeConfig={routeConfig} />);
|
||||
|
||||
// Hot Module Replacement API
|
||||
/* istanbul ignore if */
|
||||
if (module.hot) {
|
||||
module.hot.accept('./common/routeConfig', () => {
|
||||
const nextRouteConfig = require('./common/routeConfig').default; // eslint-disable-line
|
||||
renderApp(<Root store={store} routeConfig={nextRouteConfig} />);
|
||||
});
|
||||
module.hot.accept('./Root', () => {
|
||||
const nextRoot = require('./Root').default; // eslint-disable-line
|
||||
renderApp(<Root store={store} routeConfig={routeConfig} />);
|
||||
});
|
||||
}
|
7
src/logo.svg
Normal file
7
src/logo.svg
Normal file
@ -0,0 +1,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3">
|
||||
<g fill="#61DAFB">
|
||||
<path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/>
|
||||
<circle cx="420.9" cy="296.5" r="45.7"/>
|
||||
<path d="M520.5 78.1z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.6 KiB |
9
src/styles/global.scss
Normal file
9
src/styles/global.scss
Normal file
@ -0,0 +1,9 @@
|
||||
@import './mixins';
|
||||
|
||||
// Here you put all global css rules.
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: sans-serif;
|
||||
}
|
5
src/styles/index.scss
Normal file
5
src/styles/index.scss
Normal file
@ -0,0 +1,5 @@
|
||||
// index is the entry for all styles.
|
||||
@import './global';
|
||||
@import '../features/home/style';
|
||||
@import '../features/common/style';
|
||||
@import '../features/examples/style';
|
0
src/styles/mixins.scss
Normal file
0
src/styles/mixins.scss
Normal file
30
tests/Root.test.js
Normal file
30
tests/Root.test.js
Normal file
@ -0,0 +1,30 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import configStore from '../src/common/configStore';
|
||||
import Root from '../src/Root';
|
||||
|
||||
describe('Root', () => {
|
||||
it('Root has no error', () => {
|
||||
const DumpContainer = () => <div className="container">{this.props.children}</div>;
|
||||
const NotFoundComp = () => <div className="not-found">Not found</div>;
|
||||
const routes = [{
|
||||
childRoutes: [
|
||||
{ path: '/', component: DumpContainer, childRoutes: [{ path: 'abc' }] },
|
||||
{ path: '/root', autoIndexRoute: true },
|
||||
{ path: 'relative-path', name: 'Link Name' },
|
||||
{
|
||||
path: 'sub-links',
|
||||
childRoutes: [
|
||||
{ path: 'sub-link' },
|
||||
],
|
||||
},
|
||||
{ path: '*', component: NotFoundComp },
|
||||
],
|
||||
}];
|
||||
const store = configStore();
|
||||
|
||||
shallow(
|
||||
<Root store={store} routeConfig={routes} />
|
||||
);
|
||||
});
|
||||
});
|
11
tests/features/common/PageNotFound.test.js
Normal file
11
tests/features/common/PageNotFound.test.js
Normal file
@ -0,0 +1,11 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { PageNotFound } from '../../../src/features/common';
|
||||
|
||||
describe('common/PageNotFound', () => {
|
||||
it('renders node with correct class name', () => {
|
||||
const renderedComponent = shallow(<PageNotFound />);
|
||||
|
||||
expect(renderedComponent.find('.common-page-not-found').length).toBe(1);
|
||||
});
|
||||
});
|
35
tests/features/examples/CounterPage.test.js
Normal file
35
tests/features/examples/CounterPage.test.js
Normal file
@ -0,0 +1,35 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { CounterPage } from '../../../src/features/examples/CounterPage';
|
||||
|
||||
describe('examples/CounterPage', () => {
|
||||
it('renders node with correct class name', () => {
|
||||
const props = {
|
||||
examples: {},
|
||||
actions: {},
|
||||
};
|
||||
const renderedComponent = shallow(<CounterPage {...props} />);
|
||||
|
||||
expect(renderedComponent.find('.examples-counter-page').length).toBe(1);
|
||||
});
|
||||
|
||||
it('counter actions are called when buttons clicked', () => {
|
||||
const pageProps = {
|
||||
examples: {},
|
||||
actions: {
|
||||
counterPlusOne: jest.fn(),
|
||||
counterMinusOne: jest.fn(),
|
||||
counterReset: jest.fn(),
|
||||
},
|
||||
};
|
||||
const renderedComponent = shallow(
|
||||
<CounterPage {...pageProps} />
|
||||
);
|
||||
renderedComponent.find('.btn-plus-one').simulate('click');
|
||||
renderedComponent.find('.btn-minus-one').simulate('click');
|
||||
renderedComponent.find('.btn-reset').simulate('click');
|
||||
expect(pageProps.actions.counterPlusOne.mock.calls.length).toBe(1);
|
||||
expect(pageProps.actions.counterMinusOne.mock.calls.length).toBe(1);
|
||||
expect(pageProps.actions.counterReset.mock.calls.length).toBe(1);
|
||||
});
|
||||
});
|
11
tests/features/examples/Layout.test.js
Normal file
11
tests/features/examples/Layout.test.js
Normal file
@ -0,0 +1,11 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { Layout } from '../../../src/features/examples';
|
||||
|
||||
describe('examples/Layout', () => {
|
||||
it('renders node with correct class name', () => {
|
||||
const renderedComponent = shallow(<Layout />);
|
||||
|
||||
expect(renderedComponent.find('.examples-layout').length).toBe(1);
|
||||
});
|
||||
});
|
51
tests/features/examples/RedditListPage.test.js
Normal file
51
tests/features/examples/RedditListPage.test.js
Normal file
@ -0,0 +1,51 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { RedditListPage } from '../../../src/features/examples/RedditListPage';
|
||||
|
||||
describe('examples/RedditListPage', () => {
|
||||
it('renders node with correct class name', () => {
|
||||
const props = {
|
||||
examples: { redditList: [] },
|
||||
actions: {},
|
||||
};
|
||||
const renderedComponent = shallow(<RedditListPage {...props} />);
|
||||
|
||||
expect(renderedComponent.find('.examples-reddit-list-page').length).toBe(1);
|
||||
expect(renderedComponent.find('.no-items-tip').length).toBe(1);
|
||||
});
|
||||
it("renders list items when there's data", () => {
|
||||
const props = {
|
||||
examples: { redditList: [{ data: { id: 'id', title: 'title', url: 'url' } }] },
|
||||
actions: {},
|
||||
};
|
||||
const renderedComponent = shallow(<RedditListPage {...props} />);
|
||||
|
||||
expect(renderedComponent.find('.examples-reddit-list-page').length).toBe(1);
|
||||
});
|
||||
|
||||
it('should disable fetch button when fetching reddit', () => {
|
||||
const pageProps = {
|
||||
examples: {
|
||||
redditList: [],
|
||||
fetchRedditListPending: true,
|
||||
},
|
||||
actions: {},
|
||||
};
|
||||
const renderedComponent = shallow(<RedditListPage {...pageProps} />);
|
||||
|
||||
expect(renderedComponent.find('.btn-fetch-reddit[disabled]').length).toBe(1);
|
||||
});
|
||||
|
||||
it('should show error if fetch failed', () => {
|
||||
const pageProps = {
|
||||
examples: {
|
||||
redditList: [],
|
||||
fetchRedditListError: new Error('server error'),
|
||||
},
|
||||
actions: {},
|
||||
};
|
||||
const renderedComponent = shallow(<RedditListPage {...pageProps} />);
|
||||
|
||||
expect(renderedComponent.find('.fetch-list-error').length).toBe(1);
|
||||
});
|
||||
});
|
15
tests/features/examples/SidePanel.test.js
Normal file
15
tests/features/examples/SidePanel.test.js
Normal file
@ -0,0 +1,15 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { SidePanel } from '../../../src/features/examples/SidePanel';
|
||||
|
||||
describe('examples/SidePanel', () => {
|
||||
it('renders node with correct class name', () => {
|
||||
const props = {
|
||||
examples: {},
|
||||
actions: {},
|
||||
};
|
||||
const renderedComponent = shallow(<SidePanel {...props} />);
|
||||
|
||||
expect(renderedComponent.find('.examples-side-panel').length).toBe(1);
|
||||
});
|
||||
});
|
15
tests/features/examples/WelcomePage.test.js
Normal file
15
tests/features/examples/WelcomePage.test.js
Normal file
@ -0,0 +1,15 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { WelcomePage } from '../../../src/features/examples/WelcomePage';
|
||||
|
||||
describe('examples/WelcomePage', () => {
|
||||
it('renders node with correct class name', () => {
|
||||
const props = {
|
||||
examples: {},
|
||||
actions: {},
|
||||
};
|
||||
const renderedComponent = shallow(<WelcomePage {...props} />);
|
||||
|
||||
expect(renderedComponent.find('.examples-welcome-page').length).toBe(1);
|
||||
});
|
||||
});
|
28
tests/features/examples/redux/counterMinusOne.test.js
Normal file
28
tests/features/examples/redux/counterMinusOne.test.js
Normal file
@ -0,0 +1,28 @@
|
||||
import {
|
||||
EXAMPLES_COUNTER_MINUS_ONE,
|
||||
} from '../../../../src/features/examples/redux/constants';
|
||||
|
||||
import {
|
||||
counterMinusOne,
|
||||
reducer,
|
||||
} from '../../../../src/features/examples/redux/counterMinusOne';
|
||||
|
||||
describe('examples/redux/counterMinusOne', () => {
|
||||
it('returns correct action by counterMinusOne', () => {
|
||||
expect(counterMinusOne()).toHaveProperty('type', EXAMPLES_COUNTER_MINUS_ONE);
|
||||
});
|
||||
|
||||
it('handles action type EXAMPLES_COUNTER_MINUS_ONE correctly', () => {
|
||||
const prevState = { count: 3 };
|
||||
// TODO: use real expected state.
|
||||
const expectedState = { count: 2 };
|
||||
|
||||
const state = reducer(
|
||||
prevState,
|
||||
{ type: EXAMPLES_COUNTER_MINUS_ONE }
|
||||
);
|
||||
// Should be immutable
|
||||
expect(state).not.toBe(prevState);
|
||||
expect(state).toEqual(expectedState);
|
||||
});
|
||||
});
|
25
tests/features/examples/redux/counterPlusOne.test.js
Normal file
25
tests/features/examples/redux/counterPlusOne.test.js
Normal file
@ -0,0 +1,25 @@
|
||||
import {
|
||||
EXAMPLES_COUNTER_PLUS_ONE,
|
||||
} from '../../../../src/features/examples/redux/constants';
|
||||
|
||||
import {
|
||||
counterPlusOne,
|
||||
reducer,
|
||||
} from '../../../../src/features/examples/redux/counterPlusOne';
|
||||
|
||||
describe('examples/redux/counterPlusOne', () => {
|
||||
it('returns correct action by counterPlusOne', () => {
|
||||
expect(counterPlusOne()).toHaveProperty('type', EXAMPLES_COUNTER_PLUS_ONE);
|
||||
});
|
||||
|
||||
it('handles action type EXAMPLES_COUNTER_PLUS_ONE correctly', () => {
|
||||
const prevState = { count: 0 };
|
||||
const expectedState = { count: 1 };
|
||||
const state = reducer(
|
||||
prevState,
|
||||
{ type: EXAMPLES_COUNTER_PLUS_ONE }
|
||||
);
|
||||
expect(state).not.toBe(prevState); // should be immutable
|
||||
expect(state).toEqual(expectedState); // TODO: replace this line with real case.
|
||||
});
|
||||
});
|
25
tests/features/examples/redux/counterReset.test.js
Normal file
25
tests/features/examples/redux/counterReset.test.js
Normal file
@ -0,0 +1,25 @@
|
||||
import {
|
||||
EXAMPLES_COUNTER_RESET,
|
||||
} from '../../../../src/features/examples/redux/constants';
|
||||
|
||||
import {
|
||||
counterReset,
|
||||
reducer,
|
||||
} from '../../../../src/features/examples/redux/counterReset';
|
||||
|
||||
describe('examples/redux/counterReset', () => {
|
||||
it('returns correct action by counterReset', () => {
|
||||
expect(counterReset()).toHaveProperty('type', EXAMPLES_COUNTER_RESET);
|
||||
});
|
||||
|
||||
it('handles action type EXAMPLES_COUNTER_RESET correctly', () => {
|
||||
const prevState = { count: 10 };
|
||||
const expectedState = { count: 0 };
|
||||
const state = reducer(
|
||||
prevState,
|
||||
{ type: EXAMPLES_COUNTER_RESET }
|
||||
);
|
||||
expect(state).not.toBe(prevState); // should be immutable
|
||||
expect(state).toEqual(expectedState); // TODO: replace this line with real case.
|
||||
});
|
||||
});
|
102
tests/features/examples/redux/fetchRedditList.test.js
Normal file
102
tests/features/examples/redux/fetchRedditList.test.js
Normal file
@ -0,0 +1,102 @@
|
||||
import _ from 'lodash';
|
||||
import configureMockStore from 'redux-mock-store';
|
||||
import thunk from 'redux-thunk';
|
||||
import nock from 'nock';
|
||||
|
||||
import {
|
||||
EXAMPLES_FETCH_REDDIT_LIST_BEGIN,
|
||||
EXAMPLES_FETCH_REDDIT_LIST_SUCCESS,
|
||||
EXAMPLES_FETCH_REDDIT_LIST_FAILURE,
|
||||
EXAMPLES_FETCH_REDDIT_LIST_DISMISS_ERROR,
|
||||
} from '../../../../src/features/examples/redux/constants';
|
||||
|
||||
import {
|
||||
fetchRedditList,
|
||||
dismissFetchRedditListError,
|
||||
reducer,
|
||||
} from '../../../../src/features/examples/redux/fetchRedditList';
|
||||
|
||||
const middlewares = [thunk];
|
||||
const mockStore = configureMockStore(middlewares);
|
||||
|
||||
describe('examples/redux/fetchRedditList', () => {
|
||||
afterEach(() => {
|
||||
nock.cleanAll();
|
||||
});
|
||||
|
||||
it('dispatches success action when fetchRedditList succeeds', () => {
|
||||
const list = _.times(2, i => ({
|
||||
data: {
|
||||
id: `id${i}`,
|
||||
title: `test${i}`,
|
||||
url: `http://example.com/test${i}`,
|
||||
},
|
||||
}));
|
||||
nock('http://www.reddit.com/')
|
||||
.get('/r/reactjs.json')
|
||||
.reply(200, { data: { children: list } });
|
||||
const store = mockStore({ redditReactjsList: [] });
|
||||
|
||||
return store.dispatch(fetchRedditList()).then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0]).toHaveProperty('type', EXAMPLES_FETCH_REDDIT_LIST_BEGIN);
|
||||
expect(actions[1]).toHaveProperty('type', EXAMPLES_FETCH_REDDIT_LIST_SUCCESS);
|
||||
});
|
||||
});
|
||||
|
||||
it('dispatches failure action when fetchRedditList fails', () => {
|
||||
nock('http://www.reddit.com/')
|
||||
.get('/r/reactjs.json')
|
||||
.reply(500, null);
|
||||
const store = mockStore({ redditReactjsList: [] });
|
||||
|
||||
return store.dispatch(fetchRedditList({ error: true })).catch(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0]).toHaveProperty('type', EXAMPLES_FETCH_REDDIT_LIST_BEGIN);
|
||||
expect(actions[1]).toHaveProperty('type', EXAMPLES_FETCH_REDDIT_LIST_FAILURE);
|
||||
expect(actions[1]).toHaveProperty('data.error', expect.anything());
|
||||
});
|
||||
});
|
||||
|
||||
it('returns correct action by dismissFetchRedditListError', () => {
|
||||
const expectedAction = {
|
||||
type: EXAMPLES_FETCH_REDDIT_LIST_DISMISS_ERROR,
|
||||
};
|
||||
expect(dismissFetchRedditListError()).toEqual(expectedAction);
|
||||
});
|
||||
|
||||
it('handles action type EXAMPLES_FETCH_REDDIT_LIST_BEGIN correctly', () => {
|
||||
const prevState = { fetchRedditListPending: false };
|
||||
const state = reducer(prevState, { type: EXAMPLES_FETCH_REDDIT_LIST_BEGIN });
|
||||
expect(state).not.toBe(prevState); // should be immutable
|
||||
expect(state.fetchRedditListPending).toBe(true);
|
||||
});
|
||||
|
||||
it('handles action type EXAMPLES_FETCH_REDDIT_LIST_SUCCESS correctly', () => {
|
||||
const prevState = { fetchRedditListPending: true };
|
||||
const state = reducer(prevState, {
|
||||
type: EXAMPLES_FETCH_REDDIT_LIST_SUCCESS,
|
||||
data: { data: { children: [] } },
|
||||
});
|
||||
expect(state).not.toBe(prevState); // should be immutable
|
||||
expect(state.fetchRedditListPending).toBe(false);
|
||||
});
|
||||
|
||||
it('handles action type EXAMPLES_FETCH_REDDIT_LIST_FAILURE correctly', () => {
|
||||
const prevState = { fetchRedditListPending: true };
|
||||
const state = reducer(prevState, {
|
||||
type: EXAMPLES_FETCH_REDDIT_LIST_FAILURE,
|
||||
data: { error: new Error('some error') },
|
||||
});
|
||||
expect(state).not.toBe(prevState); // should be immutable
|
||||
expect(state.fetchRedditListPending).toBe(false);
|
||||
expect(state.fetchRedditListError).toEqual(expect.anything());
|
||||
});
|
||||
|
||||
it('handles action type EXAMPLES_FETCH_REDDIT_LIST_DISMISS_ERROR correctly', () => {
|
||||
const prevState = { fetchRedditListError: new Error('some error') };
|
||||
const state = reducer(prevState, { type: EXAMPLES_FETCH_REDDIT_LIST_DISMISS_ERROR });
|
||||
expect(state).not.toBe(prevState); // should be immutable
|
||||
expect(state.fetchRedditListError).toBe(null);
|
||||
});
|
||||
});
|
14
tests/features/examples/redux/reducer.test.js
Normal file
14
tests/features/examples/redux/reducer.test.js
Normal file
@ -0,0 +1,14 @@
|
||||
import reducer from '../../../../src/features/examples/redux/reducer';
|
||||
|
||||
describe('examples/redux/reducer', () => {
|
||||
it('does nothing if no matched action', () => {
|
||||
const prevState = {};
|
||||
const state = reducer(
|
||||
prevState,
|
||||
{ type: '__UNKNOWN_ACTION_TYPE__' }
|
||||
);
|
||||
expect(state).toEqual(prevState);
|
||||
});
|
||||
|
||||
// TODO: add global reducer test if needed.
|
||||
});
|
11
tests/features/home/App.test.js
Normal file
11
tests/features/home/App.test.js
Normal file
@ -0,0 +1,11 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { App } from '../../../src/features/home';
|
||||
|
||||
describe('home/App', () => {
|
||||
it('renders node with correct class name', () => {
|
||||
const renderedComponent = shallow(<App />);
|
||||
|
||||
expect(renderedComponent.find('.home-app').length).toBe(1);
|
||||
});
|
||||
});
|
15
tests/features/home/DefaultPage.test.js
Normal file
15
tests/features/home/DefaultPage.test.js
Normal file
@ -0,0 +1,15 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { DefaultPage } from '../../../src/features/home/DefaultPage';
|
||||
|
||||
describe('home/DefaultPage', () => {
|
||||
it('renders node with correct class name', () => {
|
||||
const props = {
|
||||
home: {},
|
||||
actions: {},
|
||||
};
|
||||
const renderedComponent = shallow(<DefaultPage {...props} />);
|
||||
|
||||
expect(renderedComponent.find('.home-default-page').length).toBe(1);
|
||||
});
|
||||
});
|
7
tests/index.test.js
Normal file
7
tests/index.test.js
Normal file
@ -0,0 +1,7 @@
|
||||
// index.js should run without errors.
|
||||
describe('index', () => {
|
||||
it('index.js has no error', () => {
|
||||
document.body.innerHTML = '<div id="root"></div>';
|
||||
require('../src/index');
|
||||
});
|
||||
});
|
13
tests/setup.js
Normal file
13
tests/setup.js
Normal file
@ -0,0 +1,13 @@
|
||||
// This module will be executed before all other tests are executed,
|
||||
// so import all necessary modules which should be included for webpack compiling.
|
||||
import axios from 'axios';
|
||||
import httpAdapter from 'axios/lib/adapters/http';
|
||||
import { configure } from 'enzyme';
|
||||
import Adapter from 'enzyme-adapter-react-16';
|
||||
|
||||
configure({ adapter: new Adapter(), disableLifecycleMethods: true });
|
||||
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
axios.defaults.baseURL = 'http://localhost';
|
||||
axios.defaults.adapter = httpAdapter;
|
||||
}
|
1
tools/index.js
Normal file
1
tools/index.js
Normal file
@ -0,0 +1 @@
|
||||
// Just a placeholder.
|
Loading…
Reference in New Issue
Block a user