@etsoo/react 1.8.85 → 1.8.87

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.
@@ -57,7 +57,7 @@ export interface NotificationReactCallProps extends NotificationCallProps {
57
57
  /**
58
58
  * Buttons to override default buttons
59
59
  */
60
- buttons?: (notification: INotificationReact, callback: (event: React.MouseEvent<HTMLButtonElement>, value?: any) => Promise<boolean>) => React.ReactNode;
60
+ buttons?: (notification: INotificationReact, callback: (event: React.MouseEvent<HTMLButtonElement>, value?: any) => Promise<boolean>, base: () => React.ReactNode) => React.ReactNode;
61
61
  }
62
62
  /**
63
63
  * React notification interface
@@ -113,6 +113,7 @@ export declare abstract class NotifierReact extends NotificationContainer<React.
113
113
  * Singleton instance
114
114
  */
115
115
  static get instance(): INotifierReact;
116
+ private static _cache;
116
117
  /**
117
118
  * Update notifier
118
119
  * @param notifier Notifier
@@ -139,5 +140,10 @@ export declare abstract class NotifierReact extends NotificationContainer<React.
139
140
  * @returns Provider
140
141
  */
141
142
  createProvider(className?: string, debug?: boolean): React.FunctionComponent<React.PropsWithChildren<NotificationReactRenderProps>>;
143
+ /**
144
+ * Remove cache
145
+ * @param id Notification id
146
+ */
147
+ removeCache(id: string): void;
142
148
  }
143
149
  export {};
@@ -25,6 +25,8 @@ class NotifierReact extends notificationbase_1.NotificationContainer {
25
25
  static get instance() {
26
26
  return NotifierReact._instance;
27
27
  }
28
+ // Cache
29
+ static _cache = {};
28
30
  /**
29
31
  * Update notifier
30
32
  * @param notifier Notifier
@@ -66,7 +68,18 @@ class NotifierReact extends notificationbase_1.NotificationContainer {
66
68
  // Notifications under the align
67
69
  const notifications = state[align];
68
70
  // UI collections
69
- const ui = notifications.map((notification) => notification.render(props, className ? className + "-item" : className));
71
+ const ui = notifications.map((notification) => {
72
+ // Id
73
+ const id = notification.id;
74
+ // Try cache
75
+ const cache = NotifierReact._cache[id];
76
+ if (cache)
77
+ return cache;
78
+ const element = notification.render(props, className ? className + "-item" : className);
79
+ // Cache the element
80
+ NotifierReact._cache[id] = element;
81
+ return element;
82
+ });
70
83
  // Add to the collection
71
84
  aligns.push(this.createContainer(Number(align), ui));
72
85
  }
@@ -84,5 +97,12 @@ class NotifierReact extends notificationbase_1.NotificationContainer {
84
97
  }, this.notifications, {}, creator);
85
98
  return provider;
86
99
  }
100
+ /**
101
+ * Remove cache
102
+ * @param id Notification id
103
+ */
104
+ removeCache(id) {
105
+ delete NotifierReact._cache[id];
106
+ }
87
107
  }
88
108
  exports.NotifierReact = NotifierReact;
@@ -57,7 +57,7 @@ export interface NotificationReactCallProps extends NotificationCallProps {
57
57
  /**
58
58
  * Buttons to override default buttons
59
59
  */
60
- buttons?: (notification: INotificationReact, callback: (event: React.MouseEvent<HTMLButtonElement>, value?: any) => Promise<boolean>) => React.ReactNode;
60
+ buttons?: (notification: INotificationReact, callback: (event: React.MouseEvent<HTMLButtonElement>, value?: any) => Promise<boolean>, base: () => React.ReactNode) => React.ReactNode;
61
61
  }
62
62
  /**
63
63
  * React notification interface
@@ -113,6 +113,7 @@ export declare abstract class NotifierReact extends NotificationContainer<React.
113
113
  * Singleton instance
114
114
  */
115
115
  static get instance(): INotifierReact;
116
+ private static _cache;
116
117
  /**
117
118
  * Update notifier
118
119
  * @param notifier Notifier
@@ -139,5 +140,10 @@ export declare abstract class NotifierReact extends NotificationContainer<React.
139
140
  * @returns Provider
140
141
  */
141
142
  createProvider(className?: string, debug?: boolean): React.FunctionComponent<React.PropsWithChildren<NotificationReactRenderProps>>;
143
+ /**
144
+ * Remove cache
145
+ * @param id Notification id
146
+ */
147
+ removeCache(id: string): void;
142
148
  }
143
149
  export {};
@@ -18,6 +18,8 @@ export class NotifierReact extends NotificationContainer {
18
18
  static get instance() {
19
19
  return NotifierReact._instance;
20
20
  }
21
+ // Cache
22
+ static _cache = {};
21
23
  /**
22
24
  * Update notifier
23
25
  * @param notifier Notifier
@@ -59,7 +61,18 @@ export class NotifierReact extends NotificationContainer {
59
61
  // Notifications under the align
60
62
  const notifications = state[align];
61
63
  // UI collections
62
- const ui = notifications.map((notification) => notification.render(props, className ? className + "-item" : className));
64
+ const ui = notifications.map((notification) => {
65
+ // Id
66
+ const id = notification.id;
67
+ // Try cache
68
+ const cache = NotifierReact._cache[id];
69
+ if (cache)
70
+ return cache;
71
+ const element = notification.render(props, className ? className + "-item" : className);
72
+ // Cache the element
73
+ NotifierReact._cache[id] = element;
74
+ return element;
75
+ });
63
76
  // Add to the collection
64
77
  aligns.push(this.createContainer(Number(align), ui));
65
78
  }
@@ -77,4 +90,11 @@ export class NotifierReact extends NotificationContainer {
77
90
  }, this.notifications, {}, creator);
78
91
  return provider;
79
92
  }
93
+ /**
94
+ * Remove cache
95
+ * @param id Notification id
96
+ */
97
+ removeCache(id) {
98
+ delete NotifierReact._cache[id];
99
+ }
80
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.8.85",
3
+ "version": "1.8.87",
4
4
  "description": "TypeScript ReactJs UI Independent Framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -38,12 +38,12 @@
38
38
  "@emotion/css": "^11.13.5",
39
39
  "@emotion/react": "^11.14.0",
40
40
  "@emotion/styled": "^11.14.1",
41
- "@etsoo/appscript": "^1.6.61",
42
- "@etsoo/notificationbase": "^1.1.69",
41
+ "@etsoo/appscript": "^1.6.62",
42
+ "@etsoo/notificationbase": "^1.1.70",
43
43
  "@etsoo/shared": "^1.2.83",
44
44
  "react": "^19.2.5",
45
45
  "react-dom": "^19.2.5",
46
- "react-router-dom": "^7.14.1",
46
+ "react-router-dom": "^7.14.2",
47
47
  "react-window": "^2.2.7"
48
48
  },
49
49
  "devDependencies": {
@@ -57,7 +57,7 @@
57
57
  "@types/react-dom": "^19.2.3",
58
58
  "@vitejs/plugin-react": "^6.0.1",
59
59
  "jsdom": "^29.0.2",
60
- "typescript": "^6.0.2",
61
- "vitest": "^4.1.4"
60
+ "typescript": "^6.0.3",
61
+ "vitest": "^4.1.5"
62
62
  }
63
63
  }
@@ -86,24 +86,31 @@ export interface NotificationReactCallProps extends NotificationCallProps {
86
86
  callback: (
87
87
  event: React.MouseEvent<HTMLButtonElement>,
88
88
  value?: any
89
- ) => Promise<boolean>
89
+ ) => Promise<boolean>,
90
+ base: () => React.ReactNode
90
91
  ) => React.ReactNode;
91
92
  }
92
93
 
93
94
  /**
94
95
  * React notification interface
95
96
  */
96
- export interface INotificationReact
97
- extends INotification<React.ReactNode, NotificationReactCallProps> {}
97
+ export interface INotificationReact extends INotification<
98
+ React.ReactNode,
99
+ NotificationReactCallProps
100
+ > {}
98
101
 
99
102
  /**
100
103
  * React notification base interface
101
104
  */
102
- export interface INotificationBaseReact
103
- extends INotificaseBase<React.ReactNode, NotificationReactCallProps> {}
105
+ export interface INotificationBaseReact extends INotificaseBase<
106
+ React.ReactNode,
107
+ NotificationReactCallProps
108
+ > {}
104
109
 
105
- interface ReactNotifications
106
- extends NotificationDictionary<React.ReactNode, NotificationReactCallProps> {}
110
+ interface ReactNotifications extends NotificationDictionary<
111
+ React.ReactNode,
112
+ NotificationReactCallProps
113
+ > {}
107
114
 
108
115
  /**
109
116
  * Action to manage the notifier
@@ -131,14 +138,15 @@ export abstract class NotificationReact
131
138
  * React notification render props
132
139
  */
133
140
  export interface NotificationReactRenderProps
134
- extends NotificationRenderProps,
135
- IProviderProps<INotifierAction> {}
141
+ extends NotificationRenderProps, IProviderProps<INotifierAction> {}
136
142
 
137
143
  /**
138
144
  * Notifier interface
139
145
  */
140
- export interface INotifierReact
141
- extends INotifier<React.ReactNode, NotificationReactCallProps> {
146
+ export interface INotifierReact extends INotifier<
147
+ React.ReactNode,
148
+ NotificationReactCallProps
149
+ > {
142
150
  /**
143
151
  * Create state provider
144
152
  * @param className Style class name
@@ -168,6 +176,9 @@ export abstract class NotifierReact
168
176
  return NotifierReact._instance;
169
177
  }
170
178
 
179
+ // Cache
180
+ private static _cache: Record<string, React.ReactNode | null> = {};
181
+
171
182
  /**
172
183
  * Update notifier
173
184
  * @param notifier Notifier
@@ -234,12 +245,24 @@ export abstract class NotifierReact
234
245
  const notifications = state[align];
235
246
 
236
247
  // UI collections
237
- const ui = notifications.map((notification) =>
238
- notification.render(
248
+ const ui = notifications.map((notification) => {
249
+ // Id
250
+ const id = notification.id;
251
+
252
+ // Try cache
253
+ const cache = NotifierReact._cache[id];
254
+ if (cache) return cache;
255
+
256
+ const element = notification.render(
239
257
  props,
240
258
  className ? className + "-item" : className
241
- )
242
- );
259
+ );
260
+
261
+ // Cache the element
262
+ NotifierReact._cache[id] = element;
263
+
264
+ return element;
265
+ });
243
266
 
244
267
  // Add to the collection
245
268
  aligns.push(this.createContainer(Number(align), ui));
@@ -276,4 +299,12 @@ export abstract class NotifierReact
276
299
 
277
300
  return provider;
278
301
  }
302
+
303
+ /**
304
+ * Remove cache
305
+ * @param id Notification id
306
+ */
307
+ override removeCache(id: string): void {
308
+ delete NotifierReact._cache[id];
309
+ }
279
310
  }