@chromahq/store 0.1.0 → 0.1.1

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
@@ -256,19 +256,15 @@ function createStore(name) {
256
256
  function useStoreActions(store) {
257
257
  return React.useMemo(
258
258
  () => ({
259
- // Update state with partial data
260
259
  update: (partial) => {
261
260
  store.setState((state) => ({ ...state, ...partial }));
262
261
  },
263
- // Update state with a function
264
262
  updateWith: (updater) => {
265
263
  store.setState((state) => ({ ...state, ...updater(state) }));
266
264
  },
267
- // Replace entire state
268
265
  replace: (newState) => {
269
266
  store.setState(newState, true);
270
267
  },
271
- // Direct access to setState
272
268
  setState: store.setState.bind(store)
273
269
  }),
274
270
  [store]
@@ -294,19 +290,17 @@ function createStoreHooks() {
294
290
  const store = useStoreInstance();
295
291
  return useStoreActions(store);
296
292
  }
297
- function createActionHook(actionsFactory) {
298
- return function useCustomActions() {
299
- const store = useStoreInstance();
300
- const baseActions = useStoreActions(store);
301
- return React.useMemo(() => actionsFactory(baseActions), [baseActions]);
302
- };
293
+ function useAction(actionKey) {
294
+ const store = useStoreInstance();
295
+ const action = useCentralStore(store, (state) => state[actionKey]);
296
+ return action;
303
297
  }
304
298
  return {
305
299
  StoreProvider,
306
300
  useStore,
307
301
  useStoreInstance,
308
302
  useActions,
309
- createActionHook
303
+ useAction
310
304
  };
311
305
  }
312
306
 
package/dist/index.d.ts CHANGED
@@ -91,20 +91,8 @@ declare class StoreBuilder<T = any> {
91
91
  declare function createStore<T = any>(name?: string): StoreBuilder<T>;
92
92
 
93
93
  /**
94
- * Store actions helper (inlined from actions.ts)
95
- */
96
- declare function useStoreActions<T extends Record<string, any>>(store: CentralStore<T>): {
97
- update: (partial: Partial<T>) => void;
98
- updateWith: (updater: (state: T) => Partial<T>) => void;
99
- replace: (newState: T) => void;
100
- setState: {
101
- (partial: T | Partial<T> | ((state: T) => T | Partial<T>), replace?: false): void;
102
- (state: T | ((state: T) => T), replace: true): void;
103
- };
104
- };
105
- /**
106
- * Create a complete store hook factory with typed providers and action creators
107
- * This prevents confusion by providing only the hooks you need, not global ones
94
+ * Create store hooks for context-based state and actions.
95
+ * Use useStore for state selection and useActions for auto-wired actions.
108
96
  */
109
97
  declare function createStoreHooks<T extends Record<string, any>>(): {
110
98
  StoreProvider: ({ store, children }: {
@@ -122,7 +110,7 @@ declare function createStoreHooks<T extends Record<string, any>>(): {
122
110
  (state: T | ((state: T) => T), replace: true): void;
123
111
  };
124
112
  };
125
- createActionHook: <ActionMap extends Record<string, (...args: any[]) => void>>(actionsFactory: (actions: ReturnType<typeof useStoreActions<T>>) => ActionMap) => () => ActionMap;
113
+ useAction: <K extends keyof T>(actionKey: K) => T[K];
126
114
  };
127
115
 
128
116
  export { BridgeStore, StoreBuilder, chromeStoragePersist, createBridgeStore, createStore, createStoreHooks, useCentralDispatch, useCentralStore };
package/dist/index.es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { useSyncExternalStore, createContext, useMemo, useContext, useRef } from 'react';
2
+ import { useSyncExternalStore, createContext, useContext, useRef, useMemo } from 'react';
3
3
  import { createStore as createStore$1 } from 'zustand/vanilla';
4
4
 
5
5
  function chromeStoragePersist(options) {
@@ -236,19 +236,15 @@ function createStore(name) {
236
236
  function useStoreActions(store) {
237
237
  return useMemo(
238
238
  () => ({
239
- // Update state with partial data
240
239
  update: (partial) => {
241
240
  store.setState((state) => ({ ...state, ...partial }));
242
241
  },
243
- // Update state with a function
244
242
  updateWith: (updater) => {
245
243
  store.setState((state) => ({ ...state, ...updater(state) }));
246
244
  },
247
- // Replace entire state
248
245
  replace: (newState) => {
249
246
  store.setState(newState, true);
250
247
  },
251
- // Direct access to setState
252
248
  setState: store.setState.bind(store)
253
249
  }),
254
250
  [store]
@@ -274,19 +270,17 @@ function createStoreHooks() {
274
270
  const store = useStoreInstance();
275
271
  return useStoreActions(store);
276
272
  }
277
- function createActionHook(actionsFactory) {
278
- return function useCustomActions() {
279
- const store = useStoreInstance();
280
- const baseActions = useStoreActions(store);
281
- return useMemo(() => actionsFactory(baseActions), [baseActions]);
282
- };
273
+ function useAction(actionKey) {
274
+ const store = useStoreInstance();
275
+ const action = useCentralStore(store, (state) => state[actionKey]);
276
+ return action;
283
277
  }
284
278
  return {
285
279
  StoreProvider,
286
280
  useStore,
287
281
  useStoreInstance,
288
282
  useActions,
289
- createActionHook
283
+ useAction
290
284
  };
291
285
  }
292
286
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chromahq/store",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
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",