Skip to content

Commit ff48adf

Browse files
authored
Merge dev to master (#28)
2.0 Release
2 parents f4accd7 + 8091e0b commit ff48adf

33 files changed

+40104
-4800
lines changed

.github/workflows/ci.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: CI
2+
on: [pull_request]
3+
jobs:
4+
test:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v2
8+
- name: Cache dependencies
9+
id: cache-dependencies
10+
uses: actions/cache@v2
11+
with:
12+
path: node_modules
13+
key: ${{ runner.os }}-cache-dependencies-${{ hashFiles('package-lock.json') }}
14+
- name: Install dependencies
15+
if: steps.cache-dependencies.outputs.cache-hit != 'true'
16+
run: npm install
17+
- name: Run Tests
18+
run: npm run test
19+
build:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v2
23+
- name: Cache dependencies
24+
id: cache-dependencies
25+
uses: actions/cache@v2
26+
with:
27+
path: node_modules
28+
key: ${{ runner.os }}-cache-dependencies-${{ hashFiles('package-lock.json') }}
29+
- name: Install dependencies
30+
if: steps.cache-dependencies.outputs.cache-hit != 'true'
31+
run: npm install
32+
- name: Run Build
33+
run: npm run build
34+
lint:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v2
38+
- name: Cache dependencies
39+
id: cache-dependencies
40+
uses: actions/cache@v2
41+
with:
42+
path: node_modules
43+
key: ${{ runner.os }}-cache-dependencies-${{ hashFiles('package-lock.json') }}
44+
- name: Install dependencies
45+
if: steps.cache-dependencies.outputs.cache-hit != 'true'
46+
run: npm install
47+
- name: Run Linting
48+
run: npm run lint

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ typings/
5454
# Yarn Integrity file
5555
.yarn-integrity
5656

57-
# dotenv environment variables file
58-
.env
59-
6057
# next.js build output
6158
.next
6259

.travis.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Contributing
22

3+
## Local Development
4+
You can use the examples folder for local development. To do so, run the following:
5+
```bash
6+
npm install
7+
npm link
8+
cd example
9+
npm install
10+
npm link redux-injectors
11+
rm -rf node_modules/react
12+
rm -rf node_modules/react-dom
13+
rm -rf node_modules/react-redux
14+
15+
npm start
16+
```
17+
318
## Pull requests
419

520
Good pull requests - patches, improvements, new features - are a fantastic
@@ -26,11 +41,11 @@ included in the project:
2641

2742
```bash
2843
# Clone your fork of the repo into the current directory
29-
git clone https://github.com/<your-username>/react-boilerplate.git
44+
git clone https://github.com/<your-username>/redux-injectors.git
3045
# Navigate to the newly cloned directory
31-
cd react-boilerplate
46+
cd redux-injectors
3247
# Assign the original repo to a remote called "upstream"
33-
git remote add upstream https://github.com/react-boilerplate/react-boilerplate.git
48+
git remote add upstream https://github.com/react-boilerplate/redux-injectors.git
3449
```
3550

3651
2. If you cloned a while ago, get the latest changes from upstream:

README.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,33 @@ function createReducer(injectedReducers = {}) {
4343
const runSaga = sagaMiddleware.run;
4444
```
4545

46+
### Redux DevTools
47+
If you're using redux devtools, it's **important to set `shouldHotReload` to false**. This is because otherwise, redux devtools will re-dispatch previous actions when reducers are injected, causing unexpected behavior.
48+
49+
If using redux-toolkit:
50+
```js
51+
const store = configureStore({
52+
devTools: {
53+
shouldHotReload: false
54+
}
55+
})
56+
```
57+
58+
If not using redux-toolkit:
59+
```js
60+
import { composeWithDevTools } from 'redux-devtools-extension';
61+
62+
const composeEnhancers = composeWithDevTools({
63+
shouldHotReload: false
64+
});
65+
66+
const store = createStore(reducer, composeEnhancers(
67+
...
68+
));
69+
```
70+
71+
Unfortunately this causes a separate issue where the action history is cleared when a reducer is injected, **but it's still strongly recommended to set `shouldHotReload` to false**. There's an [open issue in the redux-devtools repo about this](https://github.com/reduxjs/redux-devtools/issues/378).
72+
4673
### Injecting your first reducer and saga
4774
After setting up the store, you will be able to start injecting reducers and sagas.
4875
```js
@@ -74,8 +101,31 @@ export default function BooksManager() {
74101
}
75102
```
76103

104+
**Note:** while the above usage should work in most cases, you might find your reducers/sagas aren't being injected in time to receive an action. This can happen, for example, if you dispatch an action inside a `useLayoutEffect` instead of a `useEffect`. In that case, `useInjectReducer` and `useInjectSaga` return boolean flags that are `true` once the reducers/sagas have finished injecting. You can check these before rendering children that depend on these reducers/sagas being injected.
105+
106+
```js
107+
import { useInjectReducer, useInjectSaga } from "redux-injectors";
108+
109+
export default function BooksManager(props) {
110+
const reducerInjected = useInjectReducer({ key: "books", reducer: booksReducer });
111+
const sagaInjected = useInjectSaga({ key: "books", saga: booksSaga });
112+
113+
if (!reducerInjected || !sagaInjected) {
114+
return null;
115+
}
116+
117+
return (
118+
<>
119+
{props.children}
120+
</>
121+
);
122+
}
123+
```
124+
125+
77126
## Documentation
78-
See the [**API reference**](docs/api.md)
127+
See the [**API reference**](docs/api.md)
128+
Or the [**example**](example)
79129

80130
## Motivation
81131
There's a few reasons why you might not want to load all your reducers and sagas upfront:

0 commit comments

Comments
 (0)