Skip to content

Commit 62d836c

Browse files
authored
Merge pull request #7 from react-boilerplate/dev
Merge dev to master
2 parents ed31c50 + 639f4a7 commit 62d836c

File tree

6 files changed

+63
-24
lines changed

6 files changed

+63
-24
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ node_js:
66

77
script:
88
- npm test -- --maxWorkers=4
9-
- npm run build
109
- npm run lint
10+
- npm run build
1111

1212
cache:
1313
directories:

package-lock.json

Lines changed: 31 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "redux-injectors",
3-
"version": "1.0.0",
3+
"version": "1.2.0",
44
"main": "dist/index.js",
55
"module": "dist/index.esm.js",
66
"types": "index.d.ts",
@@ -13,7 +13,7 @@
1313
"test": "jest",
1414
"lint": "eslint ./src",
1515
"prettify": "prettier --write",
16-
"prepublishOnly": "npm run test && npm run build"
16+
"prepublishOnly": "./scripts/check-on-master.sh && npm run test && npm run build"
1717
},
1818
"files": [
1919
"dist",

scripts/check-on-master.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
# Check to make sure we are on the master branch
4+
# See: https://stackoverflow.com/a/34658774/3006989
5+
current_branch=$(git branch | grep '*');
6+
7+
if [ "$current_branch" != "* (HEAD detached at origin/master)" -a "$current_branch" != "* master" ]; then
8+
echo "Not on master - cannot proceed, please change to master by using:\n\n git checkout master\n"
9+
exit 1
10+
fi

src/injectReducer.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,13 @@ export default ({ key, reducer }) => WrappedComponent => {
6767
*/
6868
const useInjectReducer = ({ key, reducer }) => {
6969
const store = useStore();
70-
React.useEffect(() => {
70+
71+
const isInjected = React.useRef(false);
72+
73+
if (!isInjected.current) {
7174
getInjectors(store).injectReducer(key, reducer);
72-
}, []);
75+
isInjected.current = true;
76+
}
7377
};
7478

7579
export { useInjectReducer };

src/injectSaga.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,20 @@ export default ({ key, saga, mode }) => WrappedComponent => {
8383
*/
8484
const useInjectSaga = ({ key, saga, mode }) => {
8585
const store = useStore();
86-
React.useEffect(() => {
87-
const injectors = getInjectors(store);
88-
injectors.injectSaga(key, { saga, mode });
8986

90-
return () => {
91-
injectors.ejectSaga(key);
92-
};
93-
}, []);
87+
const isInjected = React.useRef(false);
88+
89+
if (!isInjected.current) {
90+
getInjectors(store).injectSaga(key, { saga, mode });
91+
isInjected.current = true;
92+
}
93+
94+
React.useEffect(
95+
() => () => {
96+
getInjectors(store).ejectSaga(key);
97+
},
98+
[],
99+
);
94100
};
95101

96102
export { useInjectSaga };

0 commit comments

Comments
 (0)