From 4cf03ed9e292a609d851a40b0632fb028722c501 Mon Sep 17 00:00:00 2001 From: Seyi Adebajo Date: Mon, 21 May 2018 11:04:46 -0700 Subject: [PATCH] minor clean up in notification service and component --- .../app/components/notifications-service.ts | 6 +- wherehows-web/app/services/notifications.ts | 86 ++++++++++--------- 2 files changed, 48 insertions(+), 44 deletions(-) diff --git a/wherehows-web/app/components/notifications-service.ts b/wherehows-web/app/components/notifications-service.ts index 00d6fa37ed..6d173a0ee0 100644 --- a/wherehows-web/app/components/notifications-service.ts +++ b/wherehows-web/app/components/notifications-service.ts @@ -1,5 +1 @@ -import Ember from 'ember'; - -const { Component } = Ember; - -export default Component.extend({}); +export { default } from '@ember/component'; diff --git a/wherehows-web/app/services/notifications.ts b/wherehows-web/app/services/notifications.ts index 1769f8b648..2ef77dc7d9 100644 --- a/wherehows-web/app/services/notifications.ts +++ b/wherehows-web/app/services/notifications.ts @@ -1,6 +1,7 @@ import Service from '@ember/service'; import { setProperties, get, set } from '@ember/object'; import { delay } from 'wherehows-web/utils/promise-delay'; +import { action } from '@ember-decorators/object'; /** * Flag indicating the current notification queue is being processed @@ -8,8 +9,6 @@ import { delay } from 'wherehows-web/utils/promise-delay'; */ let isBuffering = false; -// type NotificationEvent = 'success' | 'error' | 'info' | 'confirm'; - /** * String literal of available notifications */ @@ -73,7 +72,7 @@ interface INotification { /** * Describes the notification resolver interface used in handling the - * dequeueing of the notification buffer + * de-queueing of the notification buffer */ interface INotificationResolver { queueAwaiter: Promise; @@ -275,7 +274,7 @@ export default class Notifications extends Service { await toastDelay; // Burn toast if (!(this.isDestroying || this.isDestroying)) { - this.actions.dismissToast.call(this); + this.dismissToast.call(this); } } } @@ -296,41 +295,50 @@ export default class Notifications extends Service { return enqueue(proxiedNotifications[type](...params), notificationsQueue); } - actions = { - /** - * Removes the current toast from view and invokes the notification resolution resolver - */ - dismissToast(this: Notifications) { - const { notificationResolution: { onComplete } }: INotification = get(this, 'toast'); - set(this, 'isShowingToast', false); + /** + * Removes the current toast from view and invokes the notification resolution resolver + */ + @action + dismissToast(this: Notifications) { + const { + notificationResolution: { onComplete } + }: INotification = get(this, 'toast'); + set(this, 'isShowingToast', false); + onComplete && onComplete(); + } + + /** + * Ignores the modal, invokes the user supplied didDismiss callback + */ + @action + dismissModal(this: Notifications) { + const { + props, + notificationResolution: { onComplete } + }: INotification = get(this, 'modal'); + + if ((props).dialogActions) { + const { didDismiss } = (props).dialogActions; + set(this, 'isShowingModal', false); + didDismiss(); onComplete && onComplete(); - }, - - /** - * Ignores the modal, invokes the user supplied didDismiss callback - */ - dismissModal(this: Notifications) { - const { props, notificationResolution: { onComplete } }: INotification = get(this, 'modal'); - - if ((props).dialogActions) { - const { didDismiss } = (props).dialogActions; - set(this, 'isShowingModal', false); - didDismiss(); - onComplete && onComplete(); - } - }, - - /** - * Confirms the dialog and invokes the user supplied didConfirm callback - */ - confirmModal(this: Notifications) { - const { props, notificationResolution: { onComplete } }: INotification = get(this, 'modal'); - if ((props).dialogActions) { - const { didConfirm } = (props).dialogActions; - set(this, 'isShowingModal', false); - didConfirm(); - onComplete && onComplete(); - } } - }; + } + + /** + * Confirms the dialog and invokes the user supplied didConfirm callback + */ + @action + confirmModal(this: Notifications) { + const { + props, + notificationResolution: { onComplete } + }: INotification = get(this, 'modal'); + if ((props).dialogActions) { + const { didConfirm } = (props).dialogActions; + set(this, 'isShowingModal', false); + didConfirm(); + onComplete && onComplete(); + } + } }