Skip to content

Commit a113a53

Browse files
author
Takeharu.Oshida
authored
Merge pull request #63 from mobilusoss/refactor/codebeat
Improve 'Block nesting too deep'
2 parents 60d6253 + 69918e4 commit a113a53

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

.codebeatignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
lib/*
2-
example/*
1+
lib/**
2+
example/**
33
karma.conf.js

src/components/Notification.js

+29-27
Original file line numberDiff line numberDiff line change
@@ -89,38 +89,40 @@ class Notification extends React.Component {
8989
}
9090
}
9191

92+
doNotification() {
93+
let opt = this.props.options;
94+
if (typeof opt.tag !== 'string') {
95+
opt.tag = 'web-notification-' + seq();
96+
}
97+
if (this.notifications[opt.tag]) {
98+
return;
99+
}
92100

101+
if (this.props.swRegistration && this.props.swRegistration.showNotification) {
102+
this.props.swRegistration.showNotification(this.props.title, opt)
103+
this.notifications[opt.tag] = {};
104+
} else {
105+
const n = new window.Notification(this.props.title, opt);
106+
n.onshow = e => {
107+
this.props.onShow(e, opt.tag);
108+
if (this.props.timeout > 0) {
109+
setTimeout(() => {
110+
this.close(n);
111+
}, this.props.timeout);
112+
}
113+
};
114+
n.onclick = e => { this.props.onClick(e, opt.tag); };
115+
n.onclose = e => { this.props.onClose(e, opt.tag); };
116+
n.onerror = e => { this.props.onError(e, opt.tag); };
117+
118+
this.notifications[opt.tag] = n;
119+
}
120+
}
93121

94122
render() {
95123
let doNotShowOnActiveWindow = this.props.disableActiveWindow && this.windowFocus;
96124
if (!this.props.ignore && this.props.title && this.state.supported && this.state.granted && !doNotShowOnActiveWindow) {
97-
98-
let opt = this.props.options;
99-
if (typeof opt.tag !== 'string') {
100-
opt.tag = 'web-notification-' + seq();
101-
}
102-
103-
if (!this.notifications[opt.tag]) {
104-
if (this.props.swRegistration && this.props.swRegistration.showNotification) {
105-
this.props.swRegistration.showNotification(this.props.title, opt)
106-
this.notifications[opt.tag] = {};
107-
} else {
108-
const n = new window.Notification(this.props.title, opt);
109-
n.onshow = e => {
110-
this.props.onShow(e, opt.tag);
111-
if (this.props.timeout > 0) {
112-
setTimeout(() => {
113-
this.close(n);
114-
}, this.props.timeout);
115-
}
116-
};
117-
n.onclick = e => { this.props.onClick(e, opt.tag); };
118-
n.onclose = e => { this.props.onClose(e, opt.tag); };
119-
n.onerror = e => { this.props.onError(e, opt.tag); };
120-
121-
this.notifications[opt.tag] = n;
122-
}
123-
}
125+
this.doNotification();
124126
}
125127

126128
// return null cause

0 commit comments

Comments
 (0)