Skip to content

Commit 9311f4d

Browse files
authored
Merge pull request #28 from wordbots/master
Use prop-types package instead of accessing PropTypes via main React package (deprecated)
2 parents 133b74a + 0c1cc0c commit 9311f4d

File tree

4 files changed

+74
-74
lines changed

4 files changed

+74
-74
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ React component which wrap web-notification.
2323

2424
```javascript
2525
Notification.propTypes = {
26-
ignore: React.PropTypes.bool,
27-
disableActiveWindow: React.PropTypes.bool,
28-
notSupported: React.PropTypes.func,
29-
onPermissionGranted: React.PropTypes.func,
30-
onPermissionDenied: React.PropTypes.func,
31-
onShow: React.PropTypes.func,
32-
onClick: React.PropTypes.func,
33-
onClose: React.PropTypes.func,
34-
onError: React.PropTypes.func,
35-
timeout: React.PropTypes.number,
36-
title: React.PropTypes.string.isRequired,
37-
options: React.PropTypes.object
26+
ignore: bool,
27+
disableActiveWindow: bool,
28+
notSupported: func,
29+
onPermissionGranted: func,
30+
onPermissionDenied: func,
31+
onShow: func,
32+
onClick: func,
33+
onClose: func,
34+
onError: func,
35+
timeout: number,
36+
title: string.isRequired,
37+
options: object
3838
};
3939

4040
```

lib/components/Notification.js

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
'use strict';
22

3-
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
4-
53
Object.defineProperty(exports, "__esModule", {
64
value: true
75
});
86

7+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8+
99
var _react = require('react');
1010

1111
var _react2 = _interopRequireDefault(_react);
1212

13+
var _propTypes = require('prop-types');
14+
1315
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1416

1517
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -29,13 +31,13 @@ var seqGen = function seqGen() {
2931
};
3032
var seq = seqGen();
3133

32-
var Notification = (function (_React$Component) {
34+
var Notification = function (_React$Component) {
3335
_inherits(Notification, _React$Component);
3436

3537
function Notification(props) {
3638
_classCallCheck(this, Notification);
3739

38-
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Notification).call(this, props));
40+
var _this = _possibleConstructorReturn(this, (Notification.__proto__ || Object.getPrototypeOf(Notification)).call(this, props));
3941

4042
var supported = false;
4143
var granted = false;
@@ -44,8 +46,6 @@ var Notification = (function (_React$Component) {
4446
if (window.Notification.permission === PERMISSION_GRANTED) {
4547
granted = true;
4648
}
47-
} else {
48-
supported = false;
4949
}
5050

5151
_this.state = {
@@ -137,34 +137,32 @@ var Notification = (function (_React$Component) {
137137

138138
var doNotShowOnActiveWindow = this.props.disableActiveWindow && this.windowFocus;
139139
if (!this.props.ignore && this.props.title && this.state.supported && this.state.granted && !doNotShowOnActiveWindow) {
140-
(function () {
141140

142-
var opt = _this3.props.options;
143-
if (typeof opt.tag !== 'string') {
144-
opt.tag = 'web-notification-' + seq();
145-
}
141+
var opt = this.props.options;
142+
if (typeof opt.tag !== 'string') {
143+
opt.tag = 'web-notification-' + seq();
144+
}
146145

147-
if (!_this3.notifications[opt.tag]) {
148-
var n = new window.Notification(_this3.props.title, opt);
149-
n.onshow = function (e) {
150-
_this3.props.onShow(e, opt.tag);
151-
setTimeout(function () {
152-
_this3.close(opt.tag);
153-
}, _this3.props.timeout);
154-
};
155-
n.onclick = function (e) {
156-
_this3.props.onClick(e, opt.tag);
157-
};
158-
n.onclose = function (e) {
159-
_this3.props.onClose(e, opt.tag);
160-
};
161-
n.onerror = function (e) {
162-
_this3.props.onError(e, opt.tag);
163-
};
164-
165-
_this3.notifications[opt.tag] = n;
166-
}
167-
})();
146+
if (!this.notifications[opt.tag]) {
147+
var n = new window.Notification(this.props.title, opt);
148+
n.onshow = function (e) {
149+
_this3.props.onShow(e, opt.tag);
150+
setTimeout(function () {
151+
_this3.close(n);
152+
}, _this3.props.timeout);
153+
};
154+
n.onclick = function (e) {
155+
_this3.props.onClick(e, opt.tag);
156+
};
157+
n.onclose = function (e) {
158+
_this3.props.onClose(e, opt.tag);
159+
};
160+
n.onerror = function (e) {
161+
_this3.props.onError(e, opt.tag);
162+
};
163+
164+
this.notifications[opt.tag] = n;
165+
}
168166
}
169167

170168
// return null cause
@@ -173,9 +171,9 @@ var Notification = (function (_React$Component) {
173171
}
174172
}, {
175173
key: 'close',
176-
value: function close(tag) {
177-
if (this.notifications[tag] && typeof this.notifications[tag].close === 'function') {
178-
this.notifications[tag].close();
174+
value: function close(n) {
175+
if (n && typeof n.close === 'function') {
176+
n.close();
179177
}
180178
}
181179

@@ -189,22 +187,22 @@ var Notification = (function (_React$Component) {
189187
}]);
190188

191189
return Notification;
192-
})(_react2.default.Component);
190+
}(_react2.default.Component);
193191

194192
Notification.propTypes = {
195-
ignore: _react2.default.PropTypes.bool,
196-
disableActiveWindow: _react2.default.PropTypes.bool,
197-
askAgain: _react2.default.PropTypes.bool,
198-
notSupported: _react2.default.PropTypes.func,
199-
onPermissionGranted: _react2.default.PropTypes.func,
200-
onPermissionDenied: _react2.default.PropTypes.func,
201-
onShow: _react2.default.PropTypes.func,
202-
onClick: _react2.default.PropTypes.func,
203-
onClose: _react2.default.PropTypes.func,
204-
onError: _react2.default.PropTypes.func,
205-
timeout: _react2.default.PropTypes.number,
206-
title: _react2.default.PropTypes.string.isRequired,
207-
options: _react2.default.PropTypes.object
193+
ignore: _propTypes.bool,
194+
disableActiveWindow: _propTypes.bool,
195+
askAgain: _propTypes.bool,
196+
notSupported: _propTypes.func,
197+
onPermissionGranted: _propTypes.func,
198+
onPermissionDenied: _propTypes.func,
199+
onShow: _propTypes.func,
200+
onClick: _propTypes.func,
201+
onClose: _propTypes.func,
202+
onError: _propTypes.func,
203+
timeout: _propTypes.number,
204+
title: _propTypes.string.isRequired,
205+
options: _propTypes.object
208206
};
209207

210208
Notification.defaultProps = {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"karma-safari-launcher": "^0.1.1",
5151
"karma-spec-reporter": "0.0.23",
5252
"mocha": "^2.3.4",
53+
"prop-types": "^15.5.8",
5354
"react-addons-test-utils": "^0.14.3 || ^15.0.1",
5455
"react-dom": "^0.14.3 || ^15.0.1",
5556
"rimraf": "^2.4.4",

src/components/Notification.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
import React from 'react';
4+
import { bool, func, number, object, string } from 'prop-types';
45

56
const PERMISSION_GRANTED = 'granted';
67
const PERMISSION_DENIED = 'denied';
@@ -147,19 +148,19 @@ class Notification extends React.Component {
147148
}
148149

149150
Notification.propTypes = {
150-
ignore: React.PropTypes.bool,
151-
disableActiveWindow: React.PropTypes.bool,
152-
askAgain: React.PropTypes.bool,
153-
notSupported: React.PropTypes.func,
154-
onPermissionGranted: React.PropTypes.func,
155-
onPermissionDenied: React.PropTypes.func,
156-
onShow: React.PropTypes.func,
157-
onClick: React.PropTypes.func,
158-
onClose: React.PropTypes.func,
159-
onError: React.PropTypes.func,
160-
timeout: React.PropTypes.number,
161-
title: React.PropTypes.string.isRequired,
162-
options: React.PropTypes.object
151+
ignore: bool,
152+
disableActiveWindow: bool,
153+
askAgain: bool,
154+
notSupported: func,
155+
onPermissionGranted: func,
156+
onPermissionDenied: func,
157+
onShow: func,
158+
onClick: func,
159+
onClose: func,
160+
onError: func,
161+
timeout: number,
162+
title: string.isRequired,
163+
options: object
163164
};
164165

165166
Notification.defaultProps = {

0 commit comments

Comments
 (0)