@venizia/ardor-kernel 0.4.8-6 → 0.4.8-7
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.
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { type IStorageCodec, type TStorageArea } from '../common/index.js';
|
|
2
|
+
/** What `BrowserStorage.subscribe` tells its listener about a change. */
|
|
3
|
+
export interface IStorageChange {
|
|
4
|
+
/** `true` when another tab or window changed the storage (a `storage` event); `false` for a write or removal through `BrowserStorage` in this one. */
|
|
5
|
+
isExternal: boolean;
|
|
6
|
+
}
|
|
2
7
|
/**
|
|
3
8
|
* `localStorage` and `sessionStorage` that never throw: a missing area, a blocked accessor, a quota
|
|
4
9
|
* error or text the codec cannot read gives the fallback or `false`. Nothing touches `window` at
|
|
@@ -56,11 +61,15 @@ export declare class BrowserStorage {
|
|
|
56
61
|
storage?: TStorageArea;
|
|
57
62
|
prefix: string;
|
|
58
63
|
}): number;
|
|
59
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* `listener` runs after a write through `BrowserStorage` and after another tab changes the key, and says which
|
|
66
|
+
* of the two it was in `change.isExternal`: a listener that writes back can skip the change of another tab, and one that
|
|
67
|
+
* shows "changed in another tab" can skip its own. A listener that takes no argument is called the same way.
|
|
68
|
+
*/
|
|
60
69
|
static subscribe(opts: {
|
|
61
70
|
key: string;
|
|
62
71
|
storage?: TStorageArea;
|
|
63
|
-
listener: () => void;
|
|
72
|
+
listener: (change: IStorageChange) => void;
|
|
64
73
|
}): () => void;
|
|
65
74
|
private static listen;
|
|
66
75
|
private static write;
|
|
@@ -84,11 +84,20 @@ export class BrowserStorage {
|
|
|
84
84
|
const removed = keys.filter((key) => BrowserStorage.remove({ key, storage })).length;
|
|
85
85
|
// A key not stored yet, with a write waiting for it, is under the prefix too: tell its subscribers.
|
|
86
86
|
if (prefix) {
|
|
87
|
-
BrowserStorage.notify({
|
|
87
|
+
BrowserStorage.notify({
|
|
88
|
+
key: undefined,
|
|
89
|
+
area: BrowserStorage.area({ storage }),
|
|
90
|
+
prefix,
|
|
91
|
+
isExternal: false,
|
|
92
|
+
});
|
|
88
93
|
}
|
|
89
94
|
return removed;
|
|
90
95
|
}
|
|
91
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* `listener` runs after a write through `BrowserStorage` and after another tab changes the key, and says which
|
|
98
|
+
* of the two it was in `change.isExternal`: a listener that writes back can skip the change of another tab, and one that
|
|
99
|
+
* shows "changed in another tab" can skip its own. A listener that takes no argument is called the same way.
|
|
100
|
+
*/
|
|
92
101
|
static subscribe(opts) {
|
|
93
102
|
const subscription = { ...opts };
|
|
94
103
|
if (BrowserStorage.subs.size === 0) {
|
|
@@ -115,7 +124,7 @@ export class BrowserStorage {
|
|
|
115
124
|
return BrowserStorage.safe({
|
|
116
125
|
run: () => {
|
|
117
126
|
opts.run(area);
|
|
118
|
-
BrowserStorage.notify({ key: opts.key, area });
|
|
127
|
+
BrowserStorage.notify({ key: opts.key, area, isExternal: false });
|
|
119
128
|
return true;
|
|
120
129
|
},
|
|
121
130
|
fallback: false,
|
|
@@ -125,13 +134,16 @@ export class BrowserStorage {
|
|
|
125
134
|
for (const { key, storage, listener } of BrowserStorage.subs) {
|
|
126
135
|
if ((opts.key === null || opts.key === key || (!!opts.prefix && key.startsWith(opts.prefix))) &&
|
|
127
136
|
opts.area === BrowserStorage.area({ storage })) {
|
|
128
|
-
BrowserStorage.safe({
|
|
137
|
+
BrowserStorage.safe({
|
|
138
|
+
run: () => listener({ isExternal: opts.isExternal }),
|
|
139
|
+
fallback: undefined,
|
|
140
|
+
});
|
|
129
141
|
}
|
|
130
142
|
}
|
|
131
143
|
}
|
|
132
144
|
static { this.onEvent = (event) => {
|
|
133
145
|
if ('key' in event && 'storageArea' in event) {
|
|
134
|
-
BrowserStorage.notify({ key: event.key, area: event.storageArea });
|
|
146
|
+
BrowserStorage.notify({ key: event.key, area: event.storageArea, isExternal: true });
|
|
135
147
|
}
|
|
136
148
|
}; }
|
|
137
149
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venizia/ardor-kernel",
|
|
3
|
-
"version": "0.4.8-
|
|
3
|
+
"version": "0.4.8-7",
|
|
4
4
|
"description": "ARDOR kernel - the isomorphic core of the ARDOR frontend framework: application base on IGNIS inversion, service and provider bases, request/auth constants, binding keys, the network request service, runtime config and the HTTP repository (from IGNIS). No React and no react-admin.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ardor",
|
|
@@ -73,12 +73,12 @@
|
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@size-limit/preset-small-lib": "^14.2.0",
|
|
75
75
|
"@types/bun": "^1.4.3",
|
|
76
|
-
"@venizia/dev-configs": "^0.4.8-
|
|
77
|
-
"@venizia/ignis-connectors": "^0.4.8-
|
|
78
|
-
"@venizia/ignis-filter": "^0.4.7-
|
|
79
|
-
"@venizia/ignis-helpers": "^0.4.8-
|
|
80
|
-
"@venizia/ignis-inversion": "^0.4.7-
|
|
81
|
-
"@venizia/ignis-kernel": "^0.4.8-
|
|
76
|
+
"@venizia/dev-configs": "^0.4.8-3",
|
|
77
|
+
"@venizia/ignis-connectors": "^0.4.8-6",
|
|
78
|
+
"@venizia/ignis-filter": "^0.4.7-4",
|
|
79
|
+
"@venizia/ignis-helpers": "^0.4.8-6",
|
|
80
|
+
"@venizia/ignis-inversion": "^0.4.7-3",
|
|
81
|
+
"@venizia/ignis-kernel": "^0.4.8-6",
|
|
82
82
|
"eslint": "^10.13.0",
|
|
83
83
|
"oxlint": "1.89.0",
|
|
84
84
|
"oxlint-tsgolint": "7.0.2004",
|
|
@@ -88,11 +88,11 @@
|
|
|
88
88
|
"typescript": "^6.0.3"
|
|
89
89
|
},
|
|
90
90
|
"peerDependencies": {
|
|
91
|
-
"@venizia/ignis-connectors": "^0.4.8-
|
|
92
|
-
"@venizia/ignis-filter": "^0.4.7-
|
|
93
|
-
"@venizia/ignis-helpers": "^0.4.8-
|
|
94
|
-
"@venizia/ignis-inversion": "^0.4.7-
|
|
95
|
-
"@venizia/ignis-kernel": "^0.4.8-
|
|
91
|
+
"@venizia/ignis-connectors": "^0.4.8-6",
|
|
92
|
+
"@venizia/ignis-filter": "^0.4.7-4",
|
|
93
|
+
"@venizia/ignis-helpers": "^0.4.8-6",
|
|
94
|
+
"@venizia/ignis-inversion": "^0.4.7-3",
|
|
95
|
+
"@venizia/ignis-kernel": "^0.4.8-6",
|
|
96
96
|
"reflect-metadata": ">=0.2.2"
|
|
97
97
|
},
|
|
98
98
|
"peerDependenciesMeta": {
|