@chromahq/store 0.1.3 → 0.1.5

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 CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var React = require('react');
4
+ var core = require('@chromahq/core');
4
5
  var vanilla = require('zustand/vanilla');
5
6
 
6
7
  function _interopNamespaceDefault(e) {
@@ -269,6 +270,24 @@ function createStoreHooks() {
269
270
  };
270
271
  }
271
272
 
273
+ function Store(storeName) {
274
+ return function(target, propertyKey) {
275
+ Object.defineProperty(target, propertyKey, {
276
+ get() {
277
+ try {
278
+ const diKey = storeName ? `CentralStore:${storeName}` : "CentralStore";
279
+ if (core.container && core.container.isBound(diKey)) {
280
+ return core.container.get(diKey);
281
+ }
282
+ } catch {
283
+ }
284
+ },
285
+ enumerable: true,
286
+ configurable: true
287
+ });
288
+ };
289
+ }
290
+
272
291
  class StoreBuilder {
273
292
  constructor(name = "default") {
274
293
  this.config = {
@@ -412,6 +431,7 @@ if (typeof globalThis !== "undefined") {
412
431
  }
413
432
 
414
433
  exports.BridgeStore = BridgeStore;
434
+ exports.Store = Store;
415
435
  exports.StoreBuilder = StoreBuilder;
416
436
  exports.chromeStoragePersist = chromeStoragePersist;
417
437
  exports.createActionHookForStore = createActionHookForStore;
package/dist/index.d.ts CHANGED
@@ -108,6 +108,14 @@ declare function createStoreHooks<T extends Record<string, any>>(): {
108
108
  useAction: <K extends { [K_1 in keyof T]: T[K_1] extends (...args: any[]) => any ? K_1 : never; }[keyof T]>(actionKey: K) => T[K];
109
109
  };
110
110
 
111
+ /**
112
+ * Property decorator to inject a store instance from DI container if available
113
+ * Usage:
114
+ * @Store() store: CentralStore<any>
115
+ * @Store('myStoreName') store: CentralStore<MyState>
116
+ */
117
+ declare function Store(storeName?: string): (target: any, propertyKey: string) => void;
118
+
111
119
  /**
112
120
  * Core store builder with fluent API
113
121
  */
@@ -134,5 +142,5 @@ declare class StoreBuilder<T = any> {
134
142
  */
135
143
  declare function createStore<T = any>(name?: string): StoreBuilder<T>;
136
144
 
137
- export { BridgeStore, StoreBuilder, chromeStoragePersist, createActionHookForStore, createBridgeStore, createStore, createStoreHooks, useCentralDispatch, useCentralStore };
145
+ export { BridgeStore, Store, StoreBuilder, chromeStoragePersist, createActionHookForStore, createBridgeStore, createStore, createStoreHooks, useCentralDispatch, useCentralStore };
138
146
  export type { Bridge, BridgeWithEvents, BridgeWithHandlers, CentralStore, ExtractSliceState, MergeSlices, PersistOptions, SliceCreator, StoreConfig, StoreDefinition };
package/dist/index.es.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { useSyncExternalStore, createContext, useMemo, useContext, useRef } from 'react';
3
+ import { container } from '@chromahq/core';
3
4
  import { createStore as createStore$1 } from 'zustand/vanilla';
4
5
 
5
6
  function chromeStoragePersist(options) {
@@ -249,6 +250,24 @@ function createStoreHooks() {
249
250
  };
250
251
  }
251
252
 
253
+ function Store(storeName) {
254
+ return function(target, propertyKey) {
255
+ Object.defineProperty(target, propertyKey, {
256
+ get() {
257
+ try {
258
+ const diKey = storeName ? `CentralStore:${storeName}` : "CentralStore";
259
+ if (container && container.isBound(diKey)) {
260
+ return container.get(diKey);
261
+ }
262
+ } catch {
263
+ }
264
+ },
265
+ enumerable: true,
266
+ configurable: true
267
+ });
268
+ };
269
+ }
270
+
252
271
  class StoreBuilder {
253
272
  constructor(name = "default") {
254
273
  this.config = {
@@ -391,4 +410,4 @@ if (typeof globalThis !== "undefined") {
391
410
  globalThis.initStores = init;
392
411
  }
393
412
 
394
- export { BridgeStore, StoreBuilder, chromeStoragePersist, createActionHookForStore, createBridgeStore, createStore, createStoreHooks, useCentralDispatch, useCentralStore };
413
+ export { BridgeStore, Store, StoreBuilder, chromeStoragePersist, createActionHookForStore, createBridgeStore, createStore, createStoreHooks, useCentralDispatch, useCentralStore };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chromahq/store",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
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",