Skip to content

Commit ed31c50

Browse files
authored
Merge pull request #4 from react-boilerplate/dev
Merge dev into master
2 parents 8d8ddbb + 9badb73 commit ed31c50

28 files changed

+13764
-2
lines changed

.eslintrc.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const prettierOptions = JSON.parse(
5+
fs.readFileSync(path.resolve(__dirname, '.prettierrc'), 'utf8'),
6+
);
7+
8+
module.exports = {
9+
parser: 'babel-eslint',
10+
extends: ['airbnb', 'prettier', 'prettier/react'],
11+
plugins: ['prettier', 'redux-saga', 'react', 'react-hooks'],
12+
env: {
13+
jest: true,
14+
browser: true,
15+
node: true,
16+
es6: true,
17+
},
18+
parserOptions: {
19+
ecmaVersion: 6,
20+
sourceType: 'module',
21+
ecmaFeatures: {
22+
jsx: true,
23+
},
24+
},
25+
rules: {
26+
'prettier/prettier': ['error', prettierOptions],
27+
'arrow-body-style': [2, 'as-needed'],
28+
'class-methods-use-this': 0,
29+
'import/imports-first': 0,
30+
'import/newline-after-import': 0,
31+
'import/no-dynamic-require': 0,
32+
'import/no-extraneous-dependencies': 0,
33+
'import/no-named-as-default': 0,
34+
'import/no-unresolved': 2,
35+
'import/no-webpack-loader-syntax': 0,
36+
'import/prefer-default-export': 0,
37+
'indent': [
38+
2,
39+
2,
40+
{
41+
SwitchCase: 1,
42+
},
43+
],
44+
'max-len': 0,
45+
'newline-per-chained-call': 0,
46+
'no-confusing-arrow': 0,
47+
'no-console': 1,
48+
'no-unused-vars': 2,
49+
'no-use-before-define': 0,
50+
'prefer-template': 2,
51+
'react/destructuring-assignment': 0,
52+
'react-hooks/rules-of-hooks': 'error',
53+
'react/jsx-closing-tag-location': 0,
54+
'react/forbid-prop-types': 0,
55+
'react/jsx-first-prop-new-line': [2, 'multiline'],
56+
'react/jsx-filename-extension': 0,
57+
'react/jsx-no-target-blank': 0,
58+
'react/jsx-uses-vars': 2,
59+
'react/require-default-props': 0,
60+
'react/require-extension': 0,
61+
'react/self-closing-comp': 0,
62+
'react/sort-comp': 0,
63+
'redux-saga/no-yield-in-race': 2,
64+
'redux-saga/yield-effects': 2,
65+
'require-yield': 0,
66+
67+
// Turning these off for now since enabling would cause different style then rbp
68+
'react/static-property-placement': 0,
69+
'react/jsx-props-no-spreading': 0,
70+
}
71+
};

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,6 @@ typings/
5959

6060
# next.js build output
6161
.next
62+
63+
# Transpiled code
64+
dist

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dist/
2+
node_modules/
3+
package-lock.json
4+
yarn.lock
5+
package.json

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": true,
6+
"singleQuote": true,
7+
"trailingComma": "all"
8+
}

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: node_js
2+
3+
node_js:
4+
- 'node'
5+
- 'lts/*'
6+
7+
script:
8+
- npm test -- --maxWorkers=4
9+
- npm run build
10+
- npm run lint
11+
12+
cache:
13+
directories:
14+
- node_modules

CONTRIBUTING.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Contributing
2+
3+
## Pull requests
4+
5+
Good pull requests - patches, improvements, new features - are a fantastic
6+
help. They should remain focused in scope and avoid containing unrelated
7+
commits.
8+
9+
**Please ask first** before embarking on any significant pull request (e.g.
10+
implementing features, refactoring code, porting to a different language),
11+
otherwise you risk spending a lot of time working on something that the
12+
project's developers might not want to merge into the project.
13+
14+
Please adhere to the coding conventions used throughout a project (indentation,
15+
accurate comments, etc.) and any other requirements (such as test coverage).
16+
17+
Since the `master` branch is what people actually use in production, we have a
18+
`dev` branch that unstable changes get merged into first. Only when we
19+
consider that stable we merge it into the `master` branch and release the
20+
changes for real.
21+
22+
Adhering to the following process is the best way to get your work
23+
included in the project:
24+
25+
1. [Fork](https://help.github.com/articles/fork-a-repo/) the project, clone your fork, and configure the remotes:
26+
27+
```bash
28+
# Clone your fork of the repo into the current directory
29+
git clone https://github.com/<your-username>/react-boilerplate.git
30+
# Navigate to the newly cloned directory
31+
cd react-boilerplate
32+
# Assign the original repo to a remote called "upstream"
33+
git remote add upstream https://github.com/react-boilerplate/react-boilerplate.git
34+
```
35+
36+
2. If you cloned a while ago, get the latest changes from upstream:
37+
38+
```bash
39+
git checkout dev
40+
git pull upstream dev
41+
```
42+
43+
3. Create a new topic branch (off the `dev` branch) to contain your feature, change, or fix:
44+
45+
```bash
46+
git checkout -b <topic-branch-name>
47+
```
48+
49+
4. Commit your changes in logical chunks. Please adhere to these [git commit message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) or your code is unlikely be merged into the main project. Use Git's [interactive rebase](https://help.github.com/articles/about-git-rebase/) feature to tidy up your commits before making them public.
50+
51+
5. Locally merge (or rebase) the upstream dev branch into your topic branch:
52+
53+
```bash
54+
git pull [--rebase] upstream dev
55+
```
56+
57+
6. Push your topic branch up to your fork:
58+
59+
```bash
60+
git push origin <topic-branch-name>
61+
```
62+
63+
7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/)
64+
with a clear title and description.
65+
66+
**IMPORTANT**: By submitting a patch, you agree to allow the project
67+
owners to license your work under the terms of the [MIT License](https://github.com/react-boilerplate/redux-injectors/blob/master/LICENSE.md).
68+
69+
## Tips
70+
- When changing the API, including the jsdoc comments, please remember to update the typings file: [index.d.ts](index.d.ts)

README.md

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,81 @@
1-
# injectors
2-
Asynchronous injectors for Redux reducers and sagas. As used by react-boilerplate.
1+
# redux-injectors
2+
Dynamically load [redux](https://redux.js.org/) reducers and [redux-saga](https://redux-saga.js.org/) sagas as needed, instead of loading them all upfront. This has some nice benefits, such as avoiding having to manage a big global list of reducers and sagas. It also allows more effective use of [code-splitting](https://webpack.js.org/guides/code-splitting/). See [motivation](#Motivation). As used by [react-boilerplate](https://github.com/react-boilerplate/react-boilerplate).
3+
4+
## Getting Started
5+
```bash
6+
npm install redux-injectors # (or yarn add redux-injectors)
7+
```
8+
9+
### Setting up the redux store
10+
The redux store needs to be configured to allow this library to work. The library exports a store enhancer that can be passed to the `createStore` function.
11+
```js
12+
import { createStore } from "redux";
13+
import { createInjectorsEnhancer } from "redux-injectors";
14+
15+
const store = createStore(
16+
createReducer(),
17+
initialState,
18+
createInjectorsEnhancer({
19+
createReducer,
20+
runSaga,
21+
})
22+
)
23+
```
24+
25+
Note the `createInjectorsEnhancer` function takes two options. `createReducer` should be a function that when called will return the root reducer. It's passed the injected reducers as an object of key-reducer pairs.
26+
27+
```js
28+
function createReducer(injectedReducers = {}) {
29+
const rootReducer = combineReducers({
30+
...injectedReducers,
31+
// other non-injected reducers can go here...
32+
});
33+
34+
return rootReducer
35+
}
36+
```
37+
38+
`runSaga` should usually be `sagaMiddleware.run`.
39+
40+
```js
41+
const runSaga = sagaMiddleware.run;
42+
```
43+
44+
### Injecting your first reducer and saga
45+
After setting up the store, you will be able to start injecting reducers and sagas.
46+
```js
47+
import { compose } from "redux";
48+
import { injectReducer, injectSaga } from "redux-injectors";
49+
50+
class BooksManager extends React.PureComponent {
51+
render() {
52+
return null;
53+
}
54+
}
55+
56+
export default compose(
57+
injectReducer({ key: "books", reducer: booksReducer }),
58+
injectSaga({ key: "books", saga: booksSaga })
59+
)(BooksManager);
60+
61+
```
62+
63+
Or, using hooks:
64+
```js
65+
import { useInjectReducer, useInjectSaga } from "redux-injectors";
66+
67+
export default function BooksManager() {
68+
useInjectReducer({ key: "books", reducer: booksReducer });
69+
useInjectSaga({ key: "books", saga: booksSaga });
70+
71+
return null;
72+
}
73+
```
74+
75+
## Documentation
76+
See the [**API reference**](docs/api.md)
77+
78+
## Motivation
79+
There's a few reasons why you might not want to load all your reducers and sagas upfront:
80+
1. You don't need all the reducers and sagas for every page. This library lets you only load the reducers/sagas that are needed for the page being viewed. This speeds up the page load time because you can take advantage of [code-splitting](https://webpack.js.org/guides/code-splitting/). This is also good for performance after the page has loaded, because fewer reducers and sagas are running.
81+
2. You don't want to have to manage a big list of reducers/sagas. This library lets components inject their own reducers/sagas, so you don't need to worry about adding reducers/sagas to a global list.

babel.config.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
modules: false,
7+
},
8+
],
9+
'@babel/preset-react',
10+
],
11+
plugins: [
12+
'@babel/plugin-proposal-class-properties',
13+
],
14+
env: {
15+
production: {
16+
plugins: [
17+
'@babel/plugin-transform-react-inline-elements',
18+
'@babel/plugin-transform-react-constant-elements',
19+
],
20+
},
21+
test: {
22+
plugins: [
23+
'@babel/plugin-transform-modules-commonjs',
24+
],
25+
},
26+
},
27+
};

0 commit comments

Comments
 (0)