apvarun / toastify-js

Pure JavaScript library for better notification messages
https://apvarun.github.io/toastify-js/
MIT License
2.21k stars 233 forks source link

`stopOnFocus` default value precludes disabling it #25

Closed gavinhungry closed 5 years ago

gavinhungry commented 5 years ago

The default option for stopOnFocus (#21, #22) cannot be changed to a falsey value: https://github.com/apvarun/toastify-js/blob/35c57bb3dc391ffdcf4e9ce89635c57dcaee56d4/src/toastify.js#L52

false || true is still true, so setting stopOnFocus: false will do nothing. The best way to fix this would be to instead use ES6 default parameters, something like:

init: ({
  // ... other options
  stopOnFocus = true
} = {}) => {
  // ...

  if (stopOnFocus) {
    // ...
  }
}
apvarun commented 5 years ago

Nice catch. The library is written in ES5 currently and there is an open task to move to ES6+ ( #15 ). However, this can be solved by changing the following:

this.options.stopOnFocus = options.stopOnFocus || true; ⬇️ this.options.stopOnFocus = options.stopOnFocus === undefined? true: options.stopOnFocus;

apvarun commented 5 years ago

Fixed in v1.6.1