CodeSeven / toastr

Simple javascript toast notifications
http://www.toastrjs.com
MIT License
11.94k stars 2.04k forks source link

Toastr settings are not respected on the first call #404

Open xabikos opened 8 years ago

xabikos commented 8 years ago

I am using toastr from npm with webpack. The strange behavior is that the settings that I am applying globally are not respected on the first notification but it's fine on the rest. More specifically my code looks like the following:

import toastr from 'toastr';

toastr.options = {
  closeButton: false,
  newestOnTop: false,
  progressBar: false,
  positionClass: 'toast-bottom-right',
  preventDuplicates: false,
  onclick: null,
  showDuration: 300,
  hideDuration: 1000,
  timeOut: 5000,
  extendedTimeOut: 1000,
  showEasing: 'swing',
  hideEasing: 'linear',
  showMethod: 'fadeIn',
  hideMethod: 'fadeOut',
};
const NotificationsService = {
  success(message, title) {
    toastr.success(message, title);
  },
};
export default NotificationsService;

I want all the notifications to be shown on the bottom right corner. On the first time the notification is shown to the top right corner and afterwards everything is fine. Any idea why this happens?

IndexOverflow commented 8 years ago

I'm seeing (almost) the same thing with ES6 import/export: toastr options always fall back to default. I had a quick glance and can see that the "getOptions" function expects (window).toastr.options to be set, but it's always an empty Object. Guessing the problem is the same with Webpack.

seb9465 commented 6 years ago

I'm having the same problem. On first appear, the options are ignored, but on subsequent calls, everything works fine. Is there any way to fix that ?