Попытка установить для сообщений типа ошибки в этом проекте более длительное время исчезновения, чем для других типов сообщений. Я использую Aurelia в качестве фреймворка.
В настоящее время у меня установлены следующие параметры toastr:
app.js
@inject(Endpoint.of('api'), Router, FetchConfig, AppRouterConfig, AuthService, EventAggregator)
export class App {
constructor(api, router, fetchConfig, appRouterConfig, authService, EventAggregator) {
this.api = api;
this.router = router;
this.fetchConfig = fetchConfig;
this.appRouterConfig = appRouterConfig;
this.authService = authService;
this.ea = EventAggregator;
/* Define the options for the toastr messages */
toastr.options = {
"closeButton": true,
"debug": false,
"newestOnTop": false,
"progressBar": false,
"positionClass": "toast-top-full-width",
"preventDuplicates": false,
"onclick": null,
"showDuration": "500",
"hideDuration": "1000",
"timeOut": "5000", // I want this to be 20000 for error-type messages ONLY
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
}
};
Я использую pub Aurelia /sub для того, чтобы генерировать сообщения toastr по мере необходимости. Я поместил подписку на toastr в ловушку прикрепленного жизненного цикла () класса App:
app.js
this.toastSubscription = this.ea.subscribe('toast', toast => {
toastr[toast.type](toast.message);
});
Затем, в любом другом месте проекта, где мне нужно сообщение toastrЯ использую эту публикацию:
example.js
/* For an error */
this.ea.publish('toast', {
type: 'error',
message: 'Some fancy error message',
});
/* For a success */
this.ea.publish('toast', {
type: 'success',
message: 'Much success, very achieved, wow'
})
Как бы настроить эту систему для работы с сообщениями типа ошибки, имеющими более длинный fadeOut? Я пробовал это, которое, кажется, не работает:
app.js
/* Modify the subscription to accept timeOut as an override of global options */
this.toastSubscription = this.ea.subscribe('toast', toast => {
toastr[toast.type](toast.message, {timeOut: toast.timeout});
});
example.js
this.ea.publish('toast', {
type: 'error',
message: 'Errors are love, errors are life',
timeout: 10000 // Pass in a longer timeOut than for other messages
});
Но вышеописанное не удалось.
Есть идеи?