@streamlayer/sdk-web-notifications 0.15.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -8,5 +8,10 @@ export const notifications = (instance, opts, done) => {
8
8
  instance.addNotification = instance.notifications.add;
9
9
  instance.sdk.getNotificationsStore = () => instance.notifications.getQueueStore();
10
10
  instance.sdk.getActiveNotification = () => instance.notifications.getActiveNotification();
11
+ instance.sdk.onMount(() => {
12
+ return () => {
13
+ instance.notifications.queue.drain();
14
+ };
15
+ });
11
16
  done();
12
17
  };
@@ -7,7 +7,6 @@ export type NotificationsQueueOptions = {
7
7
  export type NotificationsList = ReturnType<typeof createComputedStore<Notification[]>>;
8
8
  export declare class NotificationsQueue {
9
9
  notificationsList: ReturnType<SingleStore<Map<Notification['id'], Notification>>['getStore']>;
10
- private notifications;
11
10
  private store;
12
11
  private timeouts;
13
12
  private waitingQueue;
@@ -19,4 +18,5 @@ export declare class NotificationsQueue {
19
18
  tickWaitingQueue: () => void;
20
19
  tickActiveQueue: (notificationId: string) => void;
21
20
  closeNotification: (notificationId: string) => Notification | undefined;
21
+ drain: () => void;
22
22
  }
@@ -1,8 +1,7 @@
1
- import { SingleStore, createSingleStore } from '@streamlayer/sdk-web-interfaces';
1
+ import { createSingleStore } from '@streamlayer/sdk-web-interfaces';
2
2
  import { createLogger } from '@streamlayer/sdk-web-logger';
3
3
  export class NotificationsQueue {
4
4
  notificationsList;
5
- notifications;
6
5
  store;
7
6
  timeouts;
8
7
  waitingQueue;
@@ -16,8 +15,7 @@ export class NotificationsQueue {
16
15
  this.timeouts = new Map();
17
16
  this.waitingQueue = new Set();
18
17
  this.activeQueue = new Set();
19
- this.notifications = new SingleStore(createSingleStore(new Map()), 'notifications-queue');
20
- this.notificationsList = this.notifications.getStore();
18
+ this.notificationsList = createSingleStore(new Map());
21
19
  }
22
20
  addToQueue = (notification) => {
23
21
  if (this.store.has(notification.id)) {
@@ -90,9 +88,9 @@ export class NotificationsQueue {
90
88
  }
91
89
  const timeout = setTimeout(() => {
92
90
  const closureId = notificationId;
93
- const prevQueue = new Map(this.notifications.getValue());
91
+ const prevQueue = new Map(this.notificationsList.get());
94
92
  prevQueue.set(notification.id, notification);
95
- this.notifications.setValue(prevQueue);
93
+ this.notificationsList.set(prevQueue);
96
94
  const timeout = setTimeout(() => {
97
95
  this.logger.debug({ notificationId: closureId, delay: notification.autoHideDuration || 5000 }, 'notification hiding by autoHideDuration');
98
96
  this.closeNotification(closureId);
@@ -105,17 +103,17 @@ export class NotificationsQueue {
105
103
  this.tickWaitingQueue();
106
104
  };
107
105
  closeNotification = (notificationId) => {
108
- const prevQueue = new Map(this.notifications.getValue());
106
+ const prevQueue = new Map(this.notificationsList.get());
109
107
  const notification = prevQueue.get(notificationId);
110
108
  if (notification) {
111
109
  // do not hide notification if we have more than one notification in waiting queue,
112
110
  // because we need to show next notification immediately
113
111
  notification.hiding = !(this.waitingQueue.size >= this.options.concurrency);
114
- this.notifications.setValue(prevQueue);
112
+ this.notificationsList.set(prevQueue);
115
113
  const timeout = setTimeout(() => {
116
- const prevQueue = new Map(this.notifications.getValue());
114
+ const prevQueue = new Map(this.notificationsList.get());
117
115
  prevQueue.delete(notificationId);
118
- this.notifications.setValue(prevQueue);
116
+ this.notificationsList.set(prevQueue);
119
117
  const timeout = this.timeouts.get(notificationId);
120
118
  if (timeout !== undefined) {
121
119
  clearTimeout(timeout);
@@ -132,4 +130,12 @@ export class NotificationsQueue {
132
130
  this.logger.debug({ notificationId }, 'notification hiding');
133
131
  return notification;
134
132
  };
133
+ drain = () => {
134
+ this.store.clear();
135
+ this.timeouts.clear();
136
+ this.waitingQueue.clear();
137
+ this.activeQueue.clear();
138
+ this.notificationsList.off();
139
+ this.notificationsList.set(new Map());
140
+ };
135
141
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamlayer/sdk-web-notifications",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "type": "module",
5
5
  "main": "./lib/index.js",
6
6
  "typings": "./lib/index.d.ts",