Skip to content

Commit

Permalink
Merge pull request #63 from mobilusoss/refactor/codebeat
Browse files Browse the repository at this point in the history
Improve 'Block nesting too deep'
  • Loading branch information
Takeharu.Oshida authored Sep 17, 2019
2 parents 60d6253 + 69918e4 commit a113a53
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .codebeatignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
lib/*
example/*
lib/**
example/**
karma.conf.js
56 changes: 29 additions & 27 deletions src/components/Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,38 +89,40 @@ class Notification extends React.Component {
}
}

doNotification() {
let opt = this.props.options;
if (typeof opt.tag !== 'string') {
opt.tag = 'web-notification-' + seq();
}
if (this.notifications[opt.tag]) {
return;
}

if (this.props.swRegistration && this.props.swRegistration.showNotification) {
this.props.swRegistration.showNotification(this.props.title, opt)
this.notifications[opt.tag] = {};
} else {
const n = new window.Notification(this.props.title, opt);
n.onshow = e => {
this.props.onShow(e, opt.tag);
if (this.props.timeout > 0) {
setTimeout(() => {
this.close(n);
}, this.props.timeout);
}
};
n.onclick = e => { this.props.onClick(e, opt.tag); };
n.onclose = e => { this.props.onClose(e, opt.tag); };
n.onerror = e => { this.props.onError(e, opt.tag); };

this.notifications[opt.tag] = n;
}
}

render() {
let doNotShowOnActiveWindow = this.props.disableActiveWindow && this.windowFocus;
if (!this.props.ignore && this.props.title && this.state.supported && this.state.granted && !doNotShowOnActiveWindow) {

let opt = this.props.options;
if (typeof opt.tag !== 'string') {
opt.tag = 'web-notification-' + seq();
}

if (!this.notifications[opt.tag]) {
if (this.props.swRegistration && this.props.swRegistration.showNotification) {
this.props.swRegistration.showNotification(this.props.title, opt)
this.notifications[opt.tag] = {};
} else {
const n = new window.Notification(this.props.title, opt);
n.onshow = e => {
this.props.onShow(e, opt.tag);
if (this.props.timeout > 0) {
setTimeout(() => {
this.close(n);
}, this.props.timeout);
}
};
n.onclick = e => { this.props.onClick(e, opt.tag); };
n.onclose = e => { this.props.onClose(e, opt.tag); };
n.onerror = e => { this.props.onError(e, opt.tag); };

this.notifications[opt.tag] = n;
}
}
this.doNotification();
}

// return null cause
Expand Down

0 comments on commit a113a53

Please sign in to comment.