Skip to content

Commit 96f9d94

Browse files
authored
Merge pull request #5 from xJkit/enhance/warning-message
Enhance/warning message
2 parents f2b046c + 1668618 commit 96f9d94

File tree

6 files changed

+31
-56
lines changed

6 files changed

+31
-56
lines changed

example/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"@trendmicro/react-buttons": "^1.3.0",
99
"@trendmicro/react-modal": "^2.1.0",
1010
"prop-types": "^15.6.1",
11-
"react": "^16.3.1",
12-
"react-dom": "^16.3.1",
11+
"react": "^16.3.2",
12+
"react-dom": "^16.3.2",
1313
"react-goodbye": "link:..",
1414
"react-icons": "^2.2.7",
1515
"react-modal": "^3.3.2",

example/yarn.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3487,7 +3487,7 @@ interpret@^1.0.0:
34873487
version "1.1.0"
34883488
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.1.0.tgz#7ed1b1410c6a0e0f78cf95d3b8440c63f78b8614"
34893489

3490-
invariant@^2.2.1, invariant@^2.2.2:
3490+
invariant@^2.2.1, invariant@^2.2.2, invariant@^2.2.4:
34913491
version "2.2.4"
34923492
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
34933493
dependencies:
@@ -5635,9 +5635,9 @@ react-dev-utils@^5.0.1:
56355635
strip-ansi "3.0.1"
56365636
text-table "0.2.0"
56375637

5638-
react-dom@^16.3.1:
5639-
version "16.3.1"
5640-
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.3.1.tgz#6a3c90a4fb62f915bdbcf6204422d93a7d4ca573"
5638+
react-dom@^16.3.2:
5639+
version "16.3.2"
5640+
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.3.2.tgz#cb90f107e09536d683d84ed5d4888e9640e0e4df"
56415641
dependencies:
56425642
fbjs "^0.8.16"
56435643
loose-envify "^1.1.0"
@@ -5738,9 +5738,9 @@ react-scripts@^1.1.1:
57385738
optionalDependencies:
57395739
fsevents "^1.1.3"
57405740

5741-
react@^16.3.1:
5742-
version "16.3.1"
5743-
resolved "https://registry.yarnpkg.com/react/-/react-16.3.1.tgz#4a2da433d471251c69b6033ada30e2ed1202cfd8"
5741+
react@^16.3.2:
5742+
version "16.3.2"
5743+
resolved "https://registry.yarnpkg.com/react/-/react-16.3.2.tgz#fdc8420398533a1e58872f59091b272ce2f91ea9"
57445744
dependencies:
57455745
fbjs "^0.8.16"
57465746
loose-envify "^1.1.0"

package.json

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
"predeploy": "cd example && yarn install && yarn run build",
2626
"deploy": "gh-pages -d example/build"
2727
},
28-
"dependencies": {},
28+
"dependencies": {
29+
"invariant": "^2.2.4"
30+
},
2931
"peerDependencies": {
3032
"react": ">=16.3.0",
3133
"react-router": ">=4.0.0"
@@ -60,21 +62,12 @@
6062
"rollup-plugin-postcss": "^1.1.0",
6163
"rollup-plugin-url": "^1.3.0"
6264
},
63-
"files": [
64-
"dist"
65-
],
65+
"files": ["dist"],
6666
"jest": {
6767
"setupTestFrameworkScriptFile": "<rootDir>/scripts/jest.setup.js",
68-
"testMatch": [
69-
"<rootDir>/__tests__/*.spec.js"
70-
],
71-
"collectCoverageFrom": [
72-
"src/**/*.{js,jsx}"
73-
],
68+
"testMatch": ["<rootDir>/__tests__/*.spec.js"],
69+
"collectCoverageFrom": ["src/**/*.{js,jsx}"],
7470
"coverageDirectory": "coverage",
75-
"coverageReporters": [
76-
"html",
77-
"lcov"
78-
]
71+
"coverageReporters": ["html", "lcov"]
7972
}
8073
}

src/checkCompatible.js

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

src/index.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import React, { Fragment, createFactory } from 'react';
22
import { Prompt as ReactRouterPrompt } from 'react-router';
3+
import invariant from 'invariant';
34

4-
/** check library compatibility */
5-
import check from './checkCompatible';
6-
check();
7-
/** */
8-
5+
const __DEV__ = process.env.NODE_ENV !== 'production';
96
const GoodByeContext = React.createContext();
107

118
export class Provider extends React.Component {
@@ -15,6 +12,10 @@ export class Provider extends React.Component {
1512
isShow: false
1613
};
1714
this.pass = undefined;
15+
invariant(
16+
React.createContext,
17+
'react-goodbye only support React 16.3+ context api, please upgrade your react to the latest version.'
18+
)
1819
}
1920

2021
handleGetUserConfirm = (message, pass) => {
@@ -56,16 +57,19 @@ export const withGoodBye = BaseRouterComponent => {
5657
const factory = createFactory(BaseRouterComponent);
5758
const WithGoodBye = props => (
5859
<Provider>
59-
{({ handleGetUserConfirm }) => factory({
60-
...props,
61-
getUserConfirmation: handleGetUserConfirm
62-
})}
60+
{({ handleGetUserConfirm }) => (
61+
factory({
62+
...props,
63+
getUserConfirmation: handleGetUserConfirm
64+
})
65+
)}
6366
</Provider>
6467
);
6568

66-
if (process.env.NODE_ENV !== 'production') {
69+
if (__DEV__) {
6770
const baseRouterName = BaseRouterComponent.displayName || BaseRouterComponent.name || 'Component';
6871
WithGoodBye.displayName = `withGoodBye(${baseRouterName})`;
72+
6973
return WithGoodBye;
7074
}
7175

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2506,7 +2506,7 @@ ini@~1.3.0:
25062506
version "1.3.5"
25072507
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927"
25082508

2509-
invariant@^2.2.0, invariant@^2.2.1, invariant@^2.2.2:
2509+
invariant@^2.2.0, invariant@^2.2.1, invariant@^2.2.2, invariant@^2.2.4:
25102510
version "2.2.4"
25112511
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
25122512
dependencies:

0 commit comments

Comments
 (0)