@reykjavik/webtools 0.3.15 → 0.3.16

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/CHANGELOG.md CHANGED
@@ -4,6 +4,14 @@
4
4
 
5
5
  - ... <!-- Add new lines here. -->
6
6
 
7
+ ## 0.3.16
8
+
9
+ _2026-03-18_
10
+
11
+ - `@reykjavik/webtools/alertsStore`:
12
+ - feat: console.warn instead of throwing when recreating an extisting store
13
+ — return old store instead of creating a new one.
14
+
7
15
  ## 0.3.15
8
16
 
9
17
  _2026-03-18_
@@ -114,16 +114,6 @@ export type AlerterConfig<Level extends string = (typeof defaultAlertLevels)[num
114
114
  * @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
115
115
  */
116
116
  export declare const createAlerterStore: <Level extends string = (typeof defaultAlertLevels)[number], Type extends string = string, Flag extends string = string, Title extends boolean = false, Duration extends string = keyof typeof defaultDurations>(cfg?: AlerterConfig<Level, Type, Flag, Title, Duration>) => {
117
- /**
118
- * Singleton object with methods for showing alerts of different levels.
119
- * Pass a payload object to the method of the level you want to dispatch,
120
- * and the alert will be added to the store.
121
- *
122
- * Use `subscribeToAlerts` elsewhere in the app to subscribe to alert
123
- * notifications and display them.
124
- *
125
- * @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
126
- */
127
117
  alerter: Record<Level, (payload: AlertMessage | ({
128
118
  /**
129
119
  * A simple string containing the alert message.
@@ -167,18 +157,6 @@ export declare const createAlerterStore: <Level extends string = (typeof default
167
157
  */
168
158
  type?: Type;
169
159
  }))) => void>;
170
- /**
171
- * Subscribes to alert events. The provided callback will be called whenever a
172
- * alert is added or cleared.
173
- *
174
- * The callback is called immediately upon subscription if there are already
175
- * active alerts.
176
- *
177
- * Returns an unsubscribe function that can be called to stop receiving alert
178
- * events.
179
- *
180
- * @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
181
- */
182
160
  subscribe: (callback: (notifications: Array<{
183
161
  level: Level;
184
162
  message: AlertMessage;
@@ -73,7 +73,7 @@ const defaultDurations = {
73
73
  INDEFINITE: 0,
74
74
  };
75
75
  const DEFAULT_DEFAULT_DURATION = 'MEDIUM';
76
- const storeKeys = {};
76
+ const storeStore = {};
77
77
  /**
78
78
  * Factory function that creates an alerter store singleton with optional
79
79
  * configuration for the genarated alerts.
@@ -84,10 +84,13 @@ const storeKeys = {};
84
84
  // eslint-disable-next-line complexity
85
85
  const createAlerterStore = (cfg = {}) => {
86
86
  const STORE_KEY = cfg.key || DEFAULT_KEY;
87
- if (storeKeys[STORE_KEY]) {
88
- throw new Error(`An alerter store with key "${STORE_KEY}" already exists.`);
87
+ if (storeStore[STORE_KEY]) {
88
+ process.env.NODE_ENV !== 'production' &&
89
+ console.warn(`An alerter store with key "${STORE_KEY}" already exists.\n` +
90
+ `Returning the existing store, which may have been configured differently.\n` +
91
+ `Make sure to use unique keys if you want multiple independent stores.`);
92
+ return storeStore[STORE_KEY];
89
93
  }
90
- storeKeys[STORE_KEY] = true;
91
94
  const storgae = cfg.storage || (typeof sessionStorage !== 'undefined' ? sessionStorage : undefined);
92
95
  const alertLevels = cfg.levels || defaultAlertLevels;
93
96
  const durations = cfg.durations || defaultDurations;
@@ -304,7 +307,7 @@ const createAlerterStore = (cfg = {}) => {
304
307
  // Save the (possibly) cleaned up alerts back to the storage, because why not. :-D
305
308
  _saveAlertsToStorage();
306
309
  })();
307
- return {
310
+ return (storeStore[STORE_KEY] = {
308
311
  /**
309
312
  * Singleton object with methods for showing alerts of different levels.
310
313
  * Pass a payload object to the method of the level you want to dispatch,
@@ -329,6 +332,6 @@ const createAlerterStore = (cfg = {}) => {
329
332
  * @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
330
333
  */
331
334
  subscribe,
332
- };
335
+ });
333
336
  };
334
337
  exports.createAlerterStore = createAlerterStore;
@@ -114,16 +114,6 @@ export type AlerterConfig<Level extends string = (typeof defaultAlertLevels)[num
114
114
  * @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
115
115
  */
116
116
  export declare const createAlerterStore: <Level extends string = (typeof defaultAlertLevels)[number], Type extends string = string, Flag extends string = string, Title extends boolean = false, Duration extends string = keyof typeof defaultDurations>(cfg?: AlerterConfig<Level, Type, Flag, Title, Duration>) => {
117
- /**
118
- * Singleton object with methods for showing alerts of different levels.
119
- * Pass a payload object to the method of the level you want to dispatch,
120
- * and the alert will be added to the store.
121
- *
122
- * Use `subscribeToAlerts` elsewhere in the app to subscribe to alert
123
- * notifications and display them.
124
- *
125
- * @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
126
- */
127
117
  alerter: Record<Level, (payload: AlertMessage | ({
128
118
  /**
129
119
  * A simple string containing the alert message.
@@ -167,18 +157,6 @@ export declare const createAlerterStore: <Level extends string = (typeof default
167
157
  */
168
158
  type?: Type;
169
159
  }))) => void>;
170
- /**
171
- * Subscribes to alert events. The provided callback will be called whenever a
172
- * alert is added or cleared.
173
- *
174
- * The callback is called immediately upon subscription if there are already
175
- * active alerts.
176
- *
177
- * Returns an unsubscribe function that can be called to stop receiving alert
178
- * events.
179
- *
180
- * @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
181
- */
182
160
  subscribe: (callback: (notifications: Array<{
183
161
  level: Level;
184
162
  message: AlertMessage;
@@ -37,7 +37,7 @@ const defaultDurations = {
37
37
  INDEFINITE: 0,
38
38
  };
39
39
  const DEFAULT_DEFAULT_DURATION = 'MEDIUM';
40
- const storeKeys = {};
40
+ const storeStore = {};
41
41
  /**
42
42
  * Factory function that creates an alerter store singleton with optional
43
43
  * configuration for the genarated alerts.
@@ -48,10 +48,13 @@ const storeKeys = {};
48
48
  // eslint-disable-next-line complexity
49
49
  export const createAlerterStore = (cfg = {}) => {
50
50
  const STORE_KEY = cfg.key || DEFAULT_KEY;
51
- if (storeKeys[STORE_KEY]) {
52
- throw new Error(`An alerter store with key "${STORE_KEY}" already exists.`);
51
+ if (storeStore[STORE_KEY]) {
52
+ process.env.NODE_ENV !== 'production' &&
53
+ console.warn(`An alerter store with key "${STORE_KEY}" already exists.\n` +
54
+ `Returning the existing store, which may have been configured differently.\n` +
55
+ `Make sure to use unique keys if you want multiple independent stores.`);
56
+ return storeStore[STORE_KEY];
53
57
  }
54
- storeKeys[STORE_KEY] = true;
55
58
  const storgae = cfg.storage || (typeof sessionStorage !== 'undefined' ? sessionStorage : undefined);
56
59
  const alertLevels = cfg.levels || defaultAlertLevels;
57
60
  const durations = cfg.durations || defaultDurations;
@@ -268,7 +271,7 @@ export const createAlerterStore = (cfg = {}) => {
268
271
  // Save the (possibly) cleaned up alerts back to the storage, because why not. :-D
269
272
  _saveAlertsToStorage();
270
273
  })();
271
- return {
274
+ return (storeStore[STORE_KEY] = {
272
275
  /**
273
276
  * Singleton object with methods for showing alerts of different levels.
274
277
  * Pass a payload object to the method of the level you want to dispatch,
@@ -293,5 +296,5 @@ export const createAlerterStore = (cfg = {}) => {
293
296
  * @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#createalerterstore
294
297
  */
295
298
  subscribe,
296
- };
299
+ });
297
300
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reykjavik/webtools",
3
- "version": "0.3.15",
3
+ "version": "0.3.16",
4
4
  "description": "Misc. JS/TS helpers used by Reykjavík City's web dev teams.",
5
5
  "main": "index.js",
6
6
  "repository": "ssh://git@github.com:reykjavikcity/webtools.git",