@etsoo/notificationbase 1.1.45 → 1.1.47

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.
@@ -55,7 +55,7 @@ test('Tests for notification dismiss', () => {
55
55
  jest.runOnlyPendingTimers();
56
56
 
57
57
  // dismiss should be called 2 times
58
- expect(spy).toBeCalledTimes(2);
58
+ expect(spy).toHaveBeenCalledTimes(2);
59
59
  });
60
60
 
61
61
  test('Tests for notification container add', () => {
@@ -23,6 +23,14 @@ export interface INotifier<UI, C extends NotificationCallProps> {
23
23
  * Is model window showing
24
24
  */
25
25
  readonly isModeling: boolean;
26
+ /**
27
+ * Loading count
28
+ */
29
+ readonly loadingCount: number;
30
+ /**
31
+ * Is debug mode
32
+ */
33
+ debug: boolean;
26
34
  /**
27
35
  * Add notification
28
36
  * @param notification Notification
@@ -124,7 +132,16 @@ export interface INotifier<UI, C extends NotificationCallProps> {
124
132
  export declare abstract class NotificationContainer<UI, C extends NotificationCallProps> implements INotifier<UI, C> {
125
133
  private update;
126
134
  private lastLoading?;
127
- private loadingCount;
135
+ private _loadingCount;
136
+ /**
137
+ * Loading count
138
+ */
139
+ get loadingCount(): number;
140
+ private set loadingCount(value);
141
+ /**
142
+ * Is debug mode
143
+ */
144
+ debug: boolean;
128
145
  /**
129
146
  * Notification collection to display
130
147
  */
@@ -6,6 +6,15 @@ const Notification_1 = require("./Notification");
6
6
  * Notification container class
7
7
  */
8
8
  class NotificationContainer {
9
+ /**
10
+ * Loading count
11
+ */
12
+ get loadingCount() {
13
+ return this._loadingCount;
14
+ }
15
+ set loadingCount(value) {
16
+ this._loadingCount = value;
17
+ }
9
18
  /**
10
19
  * Is loading bar showing
11
20
  */
@@ -22,7 +31,11 @@ class NotificationContainer {
22
31
  * Constructor
23
32
  */
24
33
  constructor(update) {
25
- this.loadingCount = 0;
34
+ this._loadingCount = 0;
35
+ /**
36
+ * Is debug mode
37
+ */
38
+ this.debug = false;
26
39
  // Update callback
27
40
  this.update = update;
28
41
  // Init notification collection
@@ -191,13 +204,23 @@ class NotificationContainer {
191
204
  * @param force Force to hide, otherwise, only the last one
192
205
  */
193
206
  hideLoading(force) {
194
- // Deduct to count
195
- this.loadingCount--;
196
- if (force)
207
+ if (this.lastLoading == null) {
208
+ // Reset count when no loading
197
209
  this.loadingCount = 0;
198
- if (this.loadingCount === 0) {
199
- this.lastLoading?.dismiss();
200
- this.lastLoading = undefined;
210
+ }
211
+ else {
212
+ // Deduct to count
213
+ // Avoid negative result (-1)
214
+ if (this.loadingCount > 0) {
215
+ this.loadingCount--;
216
+ }
217
+ if (force)
218
+ this.loadingCount = 0;
219
+ // Hide the loading
220
+ if (this.loadingCount === 0) {
221
+ this.lastLoading.dismiss();
222
+ this.lastLoading = undefined;
223
+ }
201
224
  }
202
225
  }
203
226
  /**
@@ -23,6 +23,14 @@ export interface INotifier<UI, C extends NotificationCallProps> {
23
23
  * Is model window showing
24
24
  */
25
25
  readonly isModeling: boolean;
26
+ /**
27
+ * Loading count
28
+ */
29
+ readonly loadingCount: number;
30
+ /**
31
+ * Is debug mode
32
+ */
33
+ debug: boolean;
26
34
  /**
27
35
  * Add notification
28
36
  * @param notification Notification
@@ -124,7 +132,16 @@ export interface INotifier<UI, C extends NotificationCallProps> {
124
132
  export declare abstract class NotificationContainer<UI, C extends NotificationCallProps> implements INotifier<UI, C> {
125
133
  private update;
126
134
  private lastLoading?;
127
- private loadingCount;
135
+ private _loadingCount;
136
+ /**
137
+ * Loading count
138
+ */
139
+ get loadingCount(): number;
140
+ private set loadingCount(value);
141
+ /**
142
+ * Is debug mode
143
+ */
144
+ debug: boolean;
128
145
  /**
129
146
  * Notification collection to display
130
147
  */
@@ -3,6 +3,15 @@ import { NotificationAlign, NotificationMessageType, NotificationModalType, Noti
3
3
  * Notification container class
4
4
  */
5
5
  export class NotificationContainer {
6
+ /**
7
+ * Loading count
8
+ */
9
+ get loadingCount() {
10
+ return this._loadingCount;
11
+ }
12
+ set loadingCount(value) {
13
+ this._loadingCount = value;
14
+ }
6
15
  /**
7
16
  * Is loading bar showing
8
17
  */
@@ -19,7 +28,11 @@ export class NotificationContainer {
19
28
  * Constructor
20
29
  */
21
30
  constructor(update) {
22
- this.loadingCount = 0;
31
+ this._loadingCount = 0;
32
+ /**
33
+ * Is debug mode
34
+ */
35
+ this.debug = false;
23
36
  // Update callback
24
37
  this.update = update;
25
38
  // Init notification collection
@@ -188,13 +201,23 @@ export class NotificationContainer {
188
201
  * @param force Force to hide, otherwise, only the last one
189
202
  */
190
203
  hideLoading(force) {
191
- // Deduct to count
192
- this.loadingCount--;
193
- if (force)
204
+ if (this.lastLoading == null) {
205
+ // Reset count when no loading
194
206
  this.loadingCount = 0;
195
- if (this.loadingCount === 0) {
196
- this.lastLoading?.dismiss();
197
- this.lastLoading = undefined;
207
+ }
208
+ else {
209
+ // Deduct to count
210
+ // Avoid negative result (-1)
211
+ if (this.loadingCount > 0) {
212
+ this.loadingCount--;
213
+ }
214
+ if (force)
215
+ this.loadingCount = 0;
216
+ // Hide the loading
217
+ if (this.loadingCount === 0) {
218
+ this.lastLoading.dismiss();
219
+ this.lastLoading = undefined;
220
+ }
198
221
  }
199
222
  }
200
223
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/notificationbase",
3
- "version": "1.1.45",
3
+ "version": "1.1.47",
4
4
  "description": "TypeScript notification component for extending with all features described and partially implemented",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -39,6 +39,16 @@ export interface INotifier<UI, C extends NotificationCallProps> {
39
39
  */
40
40
  readonly isModeling: boolean;
41
41
 
42
+ /**
43
+ * Loading count
44
+ */
45
+ readonly loadingCount: number;
46
+
47
+ /**
48
+ * Is debug mode
49
+ */
50
+ debug: boolean;
51
+
42
52
  /**
43
53
  * Add notification
44
54
  * @param notification Notification
@@ -192,7 +202,23 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
192
202
 
193
203
  // Last loading
194
204
  private lastLoading?: INotification<UI, C>;
195
- private loadingCount = 0;
205
+
206
+ private _loadingCount = 0;
207
+
208
+ /**
209
+ * Loading count
210
+ */
211
+ get loadingCount() {
212
+ return this._loadingCount;
213
+ }
214
+ private set loadingCount(value: number) {
215
+ this._loadingCount = value;
216
+ }
217
+
218
+ /**
219
+ * Is debug mode
220
+ */
221
+ debug: boolean = false;
196
222
 
197
223
  /**
198
224
  * Notification collection to display
@@ -430,14 +456,23 @@ export abstract class NotificationContainer<UI, C extends NotificationCallProps>
430
456
  * @param force Force to hide, otherwise, only the last one
431
457
  */
432
458
  hideLoading(force?: boolean) {
433
- // Deduct to count
434
- this.loadingCount--;
459
+ if (this.lastLoading == null) {
460
+ // Reset count when no loading
461
+ this.loadingCount = 0;
462
+ } else {
463
+ // Deduct to count
464
+ // Avoid negative result (-1)
465
+ if (this.loadingCount > 0) {
466
+ this.loadingCount--;
467
+ }
435
468
 
436
- if (force) this.loadingCount = 0;
469
+ if (force) this.loadingCount = 0;
437
470
 
438
- if (this.loadingCount === 0) {
439
- this.lastLoading?.dismiss();
440
- this.lastLoading = undefined;
471
+ // Hide the loading
472
+ if (this.loadingCount === 0) {
473
+ this.lastLoading.dismiss();
474
+ this.lastLoading = undefined;
475
+ }
441
476
  }
442
477
  }
443
478