@chromahq/store 1.0.3 → 1.0.4
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/dist/index.cjs.js +7 -15
- package/dist/index.d.ts +3 -2
- package/dist/index.es.js +7 -15
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -109,7 +109,7 @@ function useStoreReset(store) {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
class BridgeStore {
|
|
112
|
-
constructor(bridge, initialState, storeName = "default") {
|
|
112
|
+
constructor(bridge, initialState, storeName = "default", readyCallbacks = /* @__PURE__ */ new Set()) {
|
|
113
113
|
this.listeners = /* @__PURE__ */ new Set();
|
|
114
114
|
this.currentState = null;
|
|
115
115
|
this.previousState = null;
|
|
@@ -134,9 +134,6 @@ class BridgeStore {
|
|
|
134
134
|
setTimeout(() => this.initialize(), 500);
|
|
135
135
|
return;
|
|
136
136
|
}
|
|
137
|
-
console.debug(
|
|
138
|
-
`BridgeStore[${this.storeName}]: Initializing with bridge (attempt ${this.initializationAttempts})...`
|
|
139
|
-
);
|
|
140
137
|
const state = await this.bridge.send(`store:${this.storeName}:getState`);
|
|
141
138
|
this.previousState = this.currentState;
|
|
142
139
|
this.currentState = state;
|
|
@@ -146,9 +143,6 @@ class BridgeStore {
|
|
|
146
143
|
this.notifyListeners();
|
|
147
144
|
this.ready = true;
|
|
148
145
|
this.notifyReady();
|
|
149
|
-
console.debug(
|
|
150
|
-
`BridgeStore[${this.storeName}]: Successfully initialized and ready after ${this.initializationAttempts} attempts`
|
|
151
|
-
);
|
|
152
146
|
} catch (error) {
|
|
153
147
|
console.error(
|
|
154
148
|
`BridgeStore[${this.storeName}]: Failed to initialize (attempt ${this.initializationAttempts}):`,
|
|
@@ -260,10 +254,7 @@ class BridgeStore {
|
|
|
260
254
|
this.previousState = initialState || null;
|
|
261
255
|
this.initialState = initialState || null;
|
|
262
256
|
this.storeName = storeName;
|
|
263
|
-
|
|
264
|
-
`BridgeStore[${this.storeName}]: Creating with bridge connected:`,
|
|
265
|
-
bridge.isConnected
|
|
266
|
-
);
|
|
257
|
+
this.readyCallbacks = readyCallbacks;
|
|
267
258
|
this.setupStateSync();
|
|
268
259
|
this.initialize();
|
|
269
260
|
}
|
|
@@ -302,8 +293,8 @@ class BridgeStore {
|
|
|
302
293
|
}
|
|
303
294
|
}
|
|
304
295
|
}
|
|
305
|
-
function createBridgeStore(bridge, initialState, storeName = "default") {
|
|
306
|
-
return new BridgeStore(bridge, initialState, storeName);
|
|
296
|
+
function createBridgeStore(bridge, initialState, storeName = "default", readyCallbacks = /* @__PURE__ */ new Set()) {
|
|
297
|
+
return new BridgeStore(bridge, initialState, storeName, readyCallbacks);
|
|
307
298
|
}
|
|
308
299
|
|
|
309
300
|
function createActionHookForStore(store, actionsFactory) {
|
|
@@ -382,6 +373,7 @@ function createStoreHooks() {
|
|
|
382
373
|
const readyCallbacks = /* @__PURE__ */ new Set();
|
|
383
374
|
class StoreBuilder {
|
|
384
375
|
constructor(name = "default") {
|
|
376
|
+
this.onReadyCallbacks = /* @__PURE__ */ new Set();
|
|
385
377
|
this.config = {
|
|
386
378
|
name,
|
|
387
379
|
slices: []
|
|
@@ -395,7 +387,7 @@ class StoreBuilder {
|
|
|
395
387
|
return this;
|
|
396
388
|
}
|
|
397
389
|
onReady(callback) {
|
|
398
|
-
|
|
390
|
+
this.onReadyCallbacks.add(callback);
|
|
399
391
|
return this;
|
|
400
392
|
}
|
|
401
393
|
/**
|
|
@@ -417,7 +409,7 @@ class StoreBuilder {
|
|
|
417
409
|
async createBaseStore() {
|
|
418
410
|
const bridge = this.config.bridge;
|
|
419
411
|
if (bridge) {
|
|
420
|
-
return createBridgeStore(bridge, void 0, this.config.name);
|
|
412
|
+
return createBridgeStore(bridge, void 0, this.config.name, this.onReadyCallbacks);
|
|
421
413
|
}
|
|
422
414
|
return this.createServiceWorkerStore();
|
|
423
415
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -68,7 +68,7 @@ declare class BridgeStore<T> implements CentralStore<T> {
|
|
|
68
68
|
private readyCallbacks;
|
|
69
69
|
private initializationAttempts;
|
|
70
70
|
private readonly maxInitializationAttempts;
|
|
71
|
-
constructor(bridge: BridgeWithEvents, initialState?: T, storeName?: string);
|
|
71
|
+
constructor(bridge: BridgeWithEvents, initialState?: T, storeName?: string, readyCallbacks?: Set<() => void>);
|
|
72
72
|
initialize: () => Promise<void>;
|
|
73
73
|
private setupStateSync;
|
|
74
74
|
private notifyListeners;
|
|
@@ -100,7 +100,7 @@ declare class BridgeStore<T> implements CentralStore<T> {
|
|
|
100
100
|
maxInitializationAttempts: number;
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
|
-
declare function createBridgeStore<T>(bridge: BridgeWithEvents, initialState?: T, storeName?: string): CentralStore<T>;
|
|
103
|
+
declare function createBridgeStore<T>(bridge: BridgeWithEvents, initialState?: T, storeName?: string, readyCallbacks?: Set<() => void>): CentralStore<T>;
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
106
|
* Generic action hook factory for any store instance.
|
|
@@ -151,6 +151,7 @@ declare function createStoreHooks<T extends Record<string, any>>(): {
|
|
|
151
151
|
*/
|
|
152
152
|
declare class StoreBuilder<T = any> {
|
|
153
153
|
private config;
|
|
154
|
+
private onReadyCallbacks;
|
|
154
155
|
constructor(name?: string);
|
|
155
156
|
/**
|
|
156
157
|
* Add state slices to the store
|
package/dist/index.es.js
CHANGED
|
@@ -89,7 +89,7 @@ function useStoreReset(store) {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
class BridgeStore {
|
|
92
|
-
constructor(bridge, initialState, storeName = "default") {
|
|
92
|
+
constructor(bridge, initialState, storeName = "default", readyCallbacks = /* @__PURE__ */ new Set()) {
|
|
93
93
|
this.listeners = /* @__PURE__ */ new Set();
|
|
94
94
|
this.currentState = null;
|
|
95
95
|
this.previousState = null;
|
|
@@ -114,9 +114,6 @@ class BridgeStore {
|
|
|
114
114
|
setTimeout(() => this.initialize(), 500);
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
117
|
-
console.debug(
|
|
118
|
-
`BridgeStore[${this.storeName}]: Initializing with bridge (attempt ${this.initializationAttempts})...`
|
|
119
|
-
);
|
|
120
117
|
const state = await this.bridge.send(`store:${this.storeName}:getState`);
|
|
121
118
|
this.previousState = this.currentState;
|
|
122
119
|
this.currentState = state;
|
|
@@ -126,9 +123,6 @@ class BridgeStore {
|
|
|
126
123
|
this.notifyListeners();
|
|
127
124
|
this.ready = true;
|
|
128
125
|
this.notifyReady();
|
|
129
|
-
console.debug(
|
|
130
|
-
`BridgeStore[${this.storeName}]: Successfully initialized and ready after ${this.initializationAttempts} attempts`
|
|
131
|
-
);
|
|
132
126
|
} catch (error) {
|
|
133
127
|
console.error(
|
|
134
128
|
`BridgeStore[${this.storeName}]: Failed to initialize (attempt ${this.initializationAttempts}):`,
|
|
@@ -240,10 +234,7 @@ class BridgeStore {
|
|
|
240
234
|
this.previousState = initialState || null;
|
|
241
235
|
this.initialState = initialState || null;
|
|
242
236
|
this.storeName = storeName;
|
|
243
|
-
|
|
244
|
-
`BridgeStore[${this.storeName}]: Creating with bridge connected:`,
|
|
245
|
-
bridge.isConnected
|
|
246
|
-
);
|
|
237
|
+
this.readyCallbacks = readyCallbacks;
|
|
247
238
|
this.setupStateSync();
|
|
248
239
|
this.initialize();
|
|
249
240
|
}
|
|
@@ -282,8 +273,8 @@ class BridgeStore {
|
|
|
282
273
|
}
|
|
283
274
|
}
|
|
284
275
|
}
|
|
285
|
-
function createBridgeStore(bridge, initialState, storeName = "default") {
|
|
286
|
-
return new BridgeStore(bridge, initialState, storeName);
|
|
276
|
+
function createBridgeStore(bridge, initialState, storeName = "default", readyCallbacks = /* @__PURE__ */ new Set()) {
|
|
277
|
+
return new BridgeStore(bridge, initialState, storeName, readyCallbacks);
|
|
287
278
|
}
|
|
288
279
|
|
|
289
280
|
function createActionHookForStore(store, actionsFactory) {
|
|
@@ -362,6 +353,7 @@ function createStoreHooks() {
|
|
|
362
353
|
const readyCallbacks = /* @__PURE__ */ new Set();
|
|
363
354
|
class StoreBuilder {
|
|
364
355
|
constructor(name = "default") {
|
|
356
|
+
this.onReadyCallbacks = /* @__PURE__ */ new Set();
|
|
365
357
|
this.config = {
|
|
366
358
|
name,
|
|
367
359
|
slices: []
|
|
@@ -375,7 +367,7 @@ class StoreBuilder {
|
|
|
375
367
|
return this;
|
|
376
368
|
}
|
|
377
369
|
onReady(callback) {
|
|
378
|
-
|
|
370
|
+
this.onReadyCallbacks.add(callback);
|
|
379
371
|
return this;
|
|
380
372
|
}
|
|
381
373
|
/**
|
|
@@ -397,7 +389,7 @@ class StoreBuilder {
|
|
|
397
389
|
async createBaseStore() {
|
|
398
390
|
const bridge = this.config.bridge;
|
|
399
391
|
if (bridge) {
|
|
400
|
-
return createBridgeStore(bridge, void 0, this.config.name);
|
|
392
|
+
return createBridgeStore(bridge, void 0, this.config.name, this.onReadyCallbacks);
|
|
401
393
|
}
|
|
402
394
|
return this.createServiceWorkerStore();
|
|
403
395
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chromahq/store",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Centralized, persistent store for Chrome extensions using zustand, accessible from service workers and React, with chrome.storage.local persistence.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs.js",
|