Skip to content

Commit 6aae839

Browse files
committed
refactor: update dependencies & fix deprecated
to make react-toastr compatible with future React 16: - updated React to 15.6.1 - removed react-addons-test-utils since it is deprecated in favor of react-dom/test-utils and react-test-renderer - removed react-addons-update since it is deprecated in favor of immutability-helper - added create-react-class to replace React.createClass - added prop-types since React will no longer ships with it - created transitionEvents.js to provide transition event compatibility
1 parent 998de6c commit 6aae839

8 files changed

+948
-440
lines changed

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@
7474
"jquery": "^3.1.0",
7575
"prismjs": "^1.5.1",
7676
"raw-loader": "^0.5.1",
77-
"react": "^15.3.2",
78-
"react-addons-test-utils": "^15.3.2",
77+
"react": "^15.6.1",
7978
"react-github-fork-ribbon": "^0.4.4",
8079
"react-scripts": "0.6.1",
8180
"rimraf": "^2.5.4",
@@ -86,9 +85,11 @@
8685
},
8786
"dependencies": {
8887
"classnames": "^2.2.5",
88+
"create-react-class": "^15.6.0",
8989
"element-class": "^0.2.2",
90+
"immutability-helper": "^2.3.0",
9091
"lodash": "^4.16.1",
91-
"react-addons-update": "^0.14.0 || ^15.0.0",
92-
"react-dom": "^0.14.0 || ^15.0.0"
92+
"react-dom": "^0.14.0 || ^15.0.0",
93+
"prop-types": "^15.5.10"
9394
}
9495
}

src/lib/ToastContainer.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ import _ from "lodash";
33
import {
44
default as React,
55
Component,
6-
PropTypes,
76
} from "react";
87

8+
import {
9+
default as PropTypes,
10+
} from "prop-types";
11+
912
import {
1013
default as update,
11-
} from "react-addons-update";
14+
} from "immutability-helper";
1215

1316
import {
1417
default as ToastMessage,

src/lib/ToastContainer.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88

99
import {
1010
default as TestUtils,
11-
} from "react-addons-test-utils";
11+
} from "react-dom/test-utils";
1212

1313
import {
1414
ToastContainer,

src/lib/ToastMessage/animationMixin.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import {
2-
default as ReactTransitionEvents,
3-
} from "react/lib/ReactTransitionEvents";
4-
51
import {
62
default as ReactDOM,
73
} from "react-dom";
@@ -10,6 +6,10 @@ import {
106
default as elementClass,
117
} from "element-class";
128

9+
import {
10+
default as ReactTransitionEvents,
11+
} from "./transitionEvents";
12+
1313
const TICK = 17;
1414
const { toString } = Object.prototype;
1515

src/lib/ToastMessage/index.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ import {
22
default as React,
33
} from "react";
44

5+
import {
6+
default as createClass,
7+
} from 'create-react-class';
8+
59
import {
610
default as update,
7-
} from "react-addons-update";
11+
} from "immutability-helper";
812

913
import {
1014
default as classNames,
@@ -102,12 +106,12 @@ const ToastMessageSpec = {
102106
},
103107
};
104108

105-
export const animation = React.createClass(update(ToastMessageSpec, {
109+
export const animation = createClass(update(ToastMessageSpec, {
106110
displayName: { $set: `ToastMessage.animation` },
107111
mixins: { $set: [animationMixin] },
108112
}));
109113

110-
export const jQuery = React.createClass(update(ToastMessageSpec, {
114+
export const jQuery = createClass(update(ToastMessageSpec, {
111115
displayName: { $set: `ToastMessage.jQuery` },
112116
mixins: { $set: [jQueryMixin] },
113117
}));
@@ -119,7 +123,7 @@ ToastMessageSpec.handleMouseEnter = noop;
119123
ToastMessageSpec.handleMouseLeave = noop;
120124
ToastMessageSpec.hideToast = noop;
121125

122-
const ToastMessage = React.createClass(ToastMessageSpec);
126+
const ToastMessage = createClass(ToastMessageSpec);
123127

124128
ToastMessage.animation = animation;
125129
ToastMessage.jQuery = jQuery;
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const endEvents = [];
2+
3+
const EVENTS = {
4+
transitionend: {
5+
transition: `transitionend`,
6+
WebkitTransition: `webkitTransitionEnd`,
7+
MozTransition: `mozTransitionEnd`,
8+
msTransition: `MSTransitionEnd`,
9+
OTransition: `oTransitionEnd`,
10+
},
11+
12+
animationend: {
13+
animation: `animationend`,
14+
WebkitAnimation: `webkitAnimationEnd`,
15+
MozAnimation: `mozAnimationEnd`,
16+
msAnimation: `MSAnimationEnd`,
17+
OAnimation: `oAnimationEnd`,
18+
},
19+
};
20+
21+
if (typeof window !== `undefined`) {
22+
const style = document.createElement(`div`).style;
23+
for (let eventType in EVENTS) {
24+
if (!EVENTS.hasOwnProperty(eventType)) {
25+
continue
26+
}
27+
const prefixes = EVENTS[eventType];
28+
for (let styleProp in prefixes) {
29+
if (prefixes.hasOwnProperty(styleProp) && styleProp in style) {
30+
endEvents.push(prefixes[styleProp]);
31+
break;
32+
}
33+
}
34+
}
35+
36+
}
37+
38+
const TransitionEvents = {
39+
addEndEventListener: function(node, eventListener) {
40+
if (endEvents.length === 0) {
41+
setTimeout(eventListener, 0);
42+
return;
43+
}
44+
endEvents.forEach(function(event) {
45+
node.addEventListener(event, eventListener, false);
46+
});
47+
},
48+
49+
removeEndEventListener: function(node, eventListener) {
50+
if (endEvents.length === 0) {
51+
return;
52+
}
53+
endEvents.forEach(function(event) {
54+
node.removeEventListener(event, eventListener, false);
55+
});
56+
},
57+
};
58+
59+
60+
export default TransitionEvents;

src/setupTests.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
global.requestAnimationFrame = function(callback) {
2+
setTimeout(callback, 0);
3+
};

0 commit comments

Comments
 (0)