Skip to content

Commit

Permalink
notification with buttons are now dismissible (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisBarranqueiro committed Dec 31, 2016
1 parent 29d9e62 commit db20977
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions src/components/Notification.js
Expand Up @@ -7,13 +7,12 @@ import {POSITIONS} from '../constants';
/**
* Create a timer
* @param {Number} dismissAfter
* @param {Array} buttons
* @param {Function} callback
* @returns {Function|null} a Timer
*/
function createTimer(dismissAfter, buttons, callback) {
if (dismissAfter > 0 && (!buttons || (buttons && buttons.length === 0))) {
return new Timer(callback, dismissAfter);
function createTimer(dismissAfter, callback) {
if (dismissAfter > 0) {
return new Timer(dismissAfter, callback);
}
return null;
}
Expand Down Expand Up @@ -68,13 +67,13 @@ export class Notification extends Component {
* @returns {void}
*/
constructor(props) {
const {dismissAfter, buttons} = props.notification;
const {dismissAfter} = props.notification;
super(props);
this._remove = this._remove.bind(this);
this._pauseTimer = this._pauseTimer.bind(this);
this._resumeTimer = this._resumeTimer.bind(this);
this.state = {
timer: createTimer(dismissAfter, buttons, this._remove)
timer: createTimer(dismissAfter, this._remove)
};
}

Expand Down Expand Up @@ -106,9 +105,9 @@ export class Notification extends Component {
* @returns {void}
*/
componentWillReceiveProps(nextProps) {
const {dismissAfter, buttons} = nextProps.notification;
const {dismissAfter} = nextProps.notification;
this.setState({
timer: createTimer(dismissAfter, buttons, this._remove)
timer: createTimer(dismissAfter, this._remove)
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/index.js
Expand Up @@ -27,7 +27,7 @@ export function convertStatus(status) {
* @param {Number} delay
* @constructor
*/
export function Timer(callback, delay) {
export function Timer(delay, callback) {
let timerId;
let start;
let remaining = delay;
Expand Down

0 comments on commit db20977

Please sign in to comment.