@chromahq/store 1.0.31 → 1.0.33
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 +19 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.es.js +19 -2
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -486,8 +486,25 @@ class BridgeStore {
|
|
|
486
486
|
}
|
|
487
487
|
}
|
|
488
488
|
}
|
|
489
|
+
const storeCache = /* @__PURE__ */ new Map();
|
|
489
490
|
function createBridgeStore(bridge, initialState, storeName = "default", readyCallbacks = /* @__PURE__ */ new Set()) {
|
|
490
|
-
|
|
491
|
+
if (storeCache.has(storeName)) {
|
|
492
|
+
const cached = storeCache.get(storeName);
|
|
493
|
+
if (STORE_ENABLE_LOGS) {
|
|
494
|
+
console.log(`BridgeStore[${storeName}]: Returning cached instance (singleton)`);
|
|
495
|
+
}
|
|
496
|
+
readyCallbacks.forEach((cb) => cached.onReady(cb));
|
|
497
|
+
return cached;
|
|
498
|
+
}
|
|
499
|
+
const store = new BridgeStore(bridge, initialState, storeName, readyCallbacks);
|
|
500
|
+
storeCache.set(storeName, store);
|
|
501
|
+
if (STORE_ENABLE_LOGS) {
|
|
502
|
+
console.log(`BridgeStore[${storeName}]: Created new instance (cached)`);
|
|
503
|
+
}
|
|
504
|
+
return store;
|
|
505
|
+
}
|
|
506
|
+
function clearStoreCache() {
|
|
507
|
+
storeCache.clear();
|
|
491
508
|
}
|
|
492
509
|
|
|
493
510
|
function createActionHookForStore(store, actionsFactory) {
|
|
@@ -803,6 +820,7 @@ async function init(storeDefinition) {
|
|
|
803
820
|
exports.BridgeStore = BridgeStore;
|
|
804
821
|
exports.StoreBuilder = StoreBuilder;
|
|
805
822
|
exports.chromeStoragePersist = chromeStoragePersist;
|
|
823
|
+
exports.clearStoreCache = clearStoreCache;
|
|
806
824
|
exports.createActionHookForStore = createActionHookForStore;
|
|
807
825
|
exports.createBridgeStore = createBridgeStore;
|
|
808
826
|
exports.createServiceWorkerStore = createServiceWorkerStore;
|
package/dist/index.d.ts
CHANGED
|
@@ -117,6 +117,7 @@ declare class BridgeStore<T> implements CentralStore<T> {
|
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
119
|
declare function createBridgeStore<T>(bridge: BridgeWithEvents, initialState?: T, storeName?: string, readyCallbacks?: Set<() => void>): CentralStore<T>;
|
|
120
|
+
declare function clearStoreCache(): void;
|
|
120
121
|
|
|
121
122
|
/**
|
|
122
123
|
* Generic action hook factory for any store instance.
|
|
@@ -209,5 +210,5 @@ declare function createUIStore<T = any>(bridge: BridgeWithEvents, initialState?:
|
|
|
209
210
|
*/
|
|
210
211
|
declare function init(storeDefinition: StoreDefinition): Promise<any>;
|
|
211
212
|
|
|
212
|
-
export { BridgeStore, StoreBuilder, chromeStoragePersist, createActionHookForStore, createBridgeStore, createServiceWorkerStore, createStore, createStoreHooks, createUIStore, init, useCentralDispatch, useCentralStore, useStoreReady, useStoreReset };
|
|
213
|
+
export { BridgeStore, StoreBuilder, chromeStoragePersist, clearStoreCache, createActionHookForStore, createBridgeStore, createServiceWorkerStore, createStore, createStoreHooks, createUIStore, init, useCentralDispatch, useCentralStore, useStoreReady, useStoreReset };
|
|
213
214
|
export type { Bridge, BridgeWithEvents, BridgeWithHandlers, CentralStore, ExtractSliceState, MergeSlices, PersistOptions, SliceCreator, StoreConfig, StoreDefinition };
|
package/dist/index.es.js
CHANGED
|
@@ -466,8 +466,25 @@ class BridgeStore {
|
|
|
466
466
|
}
|
|
467
467
|
}
|
|
468
468
|
}
|
|
469
|
+
const storeCache = /* @__PURE__ */ new Map();
|
|
469
470
|
function createBridgeStore(bridge, initialState, storeName = "default", readyCallbacks = /* @__PURE__ */ new Set()) {
|
|
470
|
-
|
|
471
|
+
if (storeCache.has(storeName)) {
|
|
472
|
+
const cached = storeCache.get(storeName);
|
|
473
|
+
if (STORE_ENABLE_LOGS) {
|
|
474
|
+
console.log(`BridgeStore[${storeName}]: Returning cached instance (singleton)`);
|
|
475
|
+
}
|
|
476
|
+
readyCallbacks.forEach((cb) => cached.onReady(cb));
|
|
477
|
+
return cached;
|
|
478
|
+
}
|
|
479
|
+
const store = new BridgeStore(bridge, initialState, storeName, readyCallbacks);
|
|
480
|
+
storeCache.set(storeName, store);
|
|
481
|
+
if (STORE_ENABLE_LOGS) {
|
|
482
|
+
console.log(`BridgeStore[${storeName}]: Created new instance (cached)`);
|
|
483
|
+
}
|
|
484
|
+
return store;
|
|
485
|
+
}
|
|
486
|
+
function clearStoreCache() {
|
|
487
|
+
storeCache.clear();
|
|
471
488
|
}
|
|
472
489
|
|
|
473
490
|
function createActionHookForStore(store, actionsFactory) {
|
|
@@ -780,4 +797,4 @@ async function init(storeDefinition) {
|
|
|
780
797
|
}
|
|
781
798
|
}
|
|
782
799
|
|
|
783
|
-
export { BridgeStore, StoreBuilder, chromeStoragePersist, createActionHookForStore, createBridgeStore, createServiceWorkerStore, createStore, createStoreHooks, createUIStore, init, useCentralDispatch, useCentralStore, useStoreReady, useStoreReset };
|
|
800
|
+
export { BridgeStore, StoreBuilder, chromeStoragePersist, clearStoreCache, createActionHookForStore, createBridgeStore, createServiceWorkerStore, createStore, createStoreHooks, createUIStore, init, useCentralDispatch, useCentralStore, useStoreReady, useStoreReset };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chromahq/store",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.33",
|
|
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",
|