beestate 0.1.11 → 0.1.12

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,13 +1,15 @@
1
1
  import type { StoreRegistry } from './types/StoreRegistry.tsx';
2
2
  export declare function createStoreRegistry(): {
3
- storeRegistry: StoreRegistry;
4
3
  StoreProvider: <TStoreName extends string = string, TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>>(props: import("./types/StoreProviderProps.tsx").StoreProviderProps<TStoreName, TStoreState, TReducerMap>) => import("react/jsx-runtime").JSX.Element;
4
+ storeRegistry: StoreRegistry;
5
+ useDispatcher: <TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>, TReducerName extends string = string, TPayload extends import("./types/ReducerPayload.tsx").ReducerPayload<TReducerMap[TReducerName]> = import("./types/ReducerPayload.tsx").ReducerPayload<TReducerMap[TReducerName]>>(reducerLink: import("./types/ReducerLink.tsx").ReducerLink<string, TStoreState, TReducerMap, TReducerName>) => import("./types/Dispatcher.tsx").Dispatcher<TPayload>;
6
+ useLatest: <TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>, TReducerName extends string = string, TReducer extends import("./types/Reducer.tsx").Reducer<TStoreState, any> = import("./types/Reducer.tsx").Reducer<TStoreState, any>>(saga: (actionName: TReducerName, payload: any, ctx: any) => void, reducerLinks: import("./types/ReducerLink.tsx").ReducerLink<string, TStoreState, TReducerMap, TReducerName>[], instanceKey?: import("./index.tsx").InstanceKey) => any;
7
+ useProp: import("./types/UseProp.tsx").UseProp;
8
+ usePropAll: import("./types/UsePropAll.tsx").UsePropAll;
9
+ usePropSelector: import("./types/UsePropSelector.tsx").UsePropSelector;
10
+ usePropSelectorAll: import("./types/UsePropSelectorAll.tsx").UsePropSelectorAll;
5
11
  useStore: {
6
12
  <TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>>(store: import("./types/Store.tsx").Store<string, TStoreState, TReducerMap>, registerInstance: import("./types/RegisterDefaultInstance.tsx").RegisterDefaultInstance<TStoreState>): void;
7
13
  <TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>>(store: import("./types/Store.tsx").Store<string, TStoreState, TReducerMap>, instanceKeys: import("./index.tsx").InstanceKey[], registerInstance: import("./types/RegisterInstance.tsx").RegisterInstance<TStoreState>): void;
8
14
  };
9
- useProp: import("./types/UseProp.tsx").UseProp;
10
- usePropAll: import("./types/UsePropAll.tsx").UsePropAll;
11
- useDispatcher: <TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>, TReducerName extends string = string, TPayload extends import("./types/ReducerPayload.tsx").ReducerPayload<TReducerMap[TReducerName]> = import("./types/ReducerPayload.tsx").ReducerPayload<TReducerMap[TReducerName]>>(reducerLink: import("./types/ReducerLink.tsx").ReducerLink<string, TStoreState, TReducerMap, TReducerName>) => import("./types/Dispatcher.tsx").Dispatcher<TPayload>;
12
- useLatest: <TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>, TReducerName extends string = string, TReducer extends import("./types/Reducer.tsx").Reducer<TStoreState, any> = import("./types/Reducer.tsx").Reducer<TStoreState, any>>(saga: (actionName: TReducerName, payload: any, ctx: any) => void, reducerLinks: import("./types/ReducerLink.tsx").ReducerLink<string, TStoreState, TReducerMap, TReducerName>[], instanceKey?: import("./index.tsx").InstanceKey) => any;
13
15
  };
@@ -0,0 +1,3 @@
1
+ import type { StoreRegistry } from './types/StoreRegistry.tsx';
2
+ import type { UsePropSelector } from './types/UsePropSelector.tsx';
3
+ export declare function createUsePropSelector(storeRegistry: StoreRegistry): UsePropSelector;
@@ -0,0 +1,3 @@
1
+ import type { StoreRegistry } from './types/StoreRegistry.tsx';
2
+ import type { UsePropSelectorAll } from './types/UsePropSelectorAll.tsx';
3
+ export declare function createUsePropSelectorAll(storeRegistry: StoreRegistry): UsePropSelectorAll;
@@ -11,7 +11,7 @@ export { createStoreRegistry } from './createStoreRegistry.tsx';
11
11
  export { InternalStore } from './InternalStore.tsx';
12
12
  export { requestState } from './requestState.tsx';
13
13
  export { requestStatus } from './requestStatus.tsx';
14
- export declare const StoreProvider: <TStoreName extends string = string, TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>>(props: import("./types/StoreProviderProps.tsx").StoreProviderProps<TStoreName, TStoreState, TReducerMap>) => import("react/jsx-runtime").JSX.Element, useDispatcher: <TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>, TReducerName extends string = string, TPayload extends import("./types/ReducerPayload.tsx").ReducerPayload<TReducerMap[TReducerName]> = import("./types/ReducerPayload.tsx").ReducerPayload<TReducerMap[TReducerName]>>(reducerLink: import("./types/ReducerLink.tsx").ReducerLink<string, TStoreState, TReducerMap, TReducerName>) => import("./types/Dispatcher.tsx").Dispatcher<TPayload>, useProp: import("./types/UseProp.tsx").UseProp, usePropAll: import("./types/UsePropAll.tsx").UsePropAll, useStore: {
14
+ export declare const StoreProvider: <TStoreName extends string = string, TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>>(props: import("./types/StoreProviderProps.tsx").StoreProviderProps<TStoreName, TStoreState, TReducerMap>) => import("react/jsx-runtime").JSX.Element, useDispatcher: <TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>, TReducerName extends string = string, TPayload extends import("./types/ReducerPayload.tsx").ReducerPayload<TReducerMap[TReducerName]> = import("./types/ReducerPayload.tsx").ReducerPayload<TReducerMap[TReducerName]>>(reducerLink: import("./types/ReducerLink.tsx").ReducerLink<string, TStoreState, TReducerMap, TReducerName>) => import("./types/Dispatcher.tsx").Dispatcher<TPayload>, useProp: import("./types/UseProp.tsx").UseProp, usePropAll: import("./types/UsePropAll.tsx").UsePropAll, usePropSelector: import("./types/UsePropSelector.tsx").UsePropSelector, usePropSelectorAll: import("./types/UsePropSelectorAll.tsx").UsePropSelectorAll, useStore: {
15
15
  <TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>>(store: import("./types/Store.tsx").Store<string, TStoreState, TReducerMap>, registerInstance: import("./types/RegisterDefaultInstance.tsx").RegisterDefaultInstance<TStoreState>): void;
16
16
  <TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>>(store: import("./types/Store.tsx").Store<string, TStoreState, TReducerMap>, instanceKeys: import("./index.tsx").InstanceKey[], registerInstance: import("./types/RegisterInstance.tsx").RegisterInstance<TStoreState>): void;
17
17
  };
@@ -0,0 +1,3 @@
1
+ import type { InstanceKey } from './types/InstanceKey.tsx';
2
+ import type { StoreState } from './types/StoreState.tsx';
3
+ export declare function pickPropAll<TStoreState extends StoreState = StoreState, TStateName extends keyof TStoreState = keyof TStoreState>(stateAll: Record<InstanceKey, TStoreState>, stateName: TStateName, instanceKeys?: InstanceKey[] | ((state: TStoreState) => boolean)): [instanceKey: InstanceKey, state: TStoreState[TStateName]][];
@@ -0,0 +1,11 @@
1
+ import type { InitializedStateLink } from './InitializedStateLink.tsx';
2
+ import type { InstanceKey } from './InstanceKey.tsx';
3
+ import type { InstanceKeyStateLink } from './InstanceKeyStateLink.tsx';
4
+ import type { ReducerMap } from './ReducerMap.tsx';
5
+ import type { StateLink } from './StateLink.tsx';
6
+ import type { StoreState } from './StoreState.tsx';
7
+ export type UsePropSelector = {
8
+ <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>>(stateLink: InitializedStateLink<string, TStoreState, TReducerMap>, instanceKey?: InstanceKey): () => boolean;
9
+ <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>>(stateLink: InstanceKeyStateLink<string, TStoreState, TReducerMap>, instanceKey?: InstanceKey): () => InstanceKey;
10
+ <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>, TStateName extends keyof TStoreState = keyof TStoreState>(stateLink: StateLink<string, TStoreState, TReducerMap, TStateName>, instanceKey?: InstanceKey): () => TStoreState[TStateName];
11
+ };
@@ -0,0 +1,7 @@
1
+ import type { InstanceKey } from './InstanceKey.tsx';
2
+ import type { ReducerMap } from './ReducerMap.tsx';
3
+ import type { StateLink } from './StateLink.tsx';
4
+ import type { StoreState } from './StoreState.tsx';
5
+ export type UsePropSelectorAll = {
6
+ <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>, TStateName extends keyof TStoreState = keyof TStoreState>(stateLink: StateLink<string, TStoreState, TReducerMap, TStateName>, instanceKeys?: InstanceKey[] | ((state: TStoreState) => boolean)): () => [instanceKey: InstanceKey, state: TStoreState[TStateName]][];
7
+ };
@@ -263,6 +263,26 @@ function createUseProp(storeRegistry) {
263
263
  };
264
264
  }
265
265
 
266
+ function pickPropAll(stateAll, stateName, instanceKeys) {
267
+ let actualInstanceKeys;
268
+ if (instanceKeys == null) {
269
+ actualInstanceKeys = [...Object.keys(stateAll), ...Object.getOwnPropertySymbols(stateAll)];
270
+ }
271
+ else if (typeof instanceKeys === `function`) {
272
+ actualInstanceKeys = [...Object.keys(stateAll), ...Object.getOwnPropertySymbols(stateAll)].filter((instanceKey) => {
273
+ return instanceKeys(stateAll[instanceKey]);
274
+ });
275
+ }
276
+ else {
277
+ actualInstanceKeys = instanceKeys.filter((instanceKey) => {
278
+ return instanceKey in stateAll;
279
+ });
280
+ }
281
+ return actualInstanceKeys.map((instanceKey) => {
282
+ return [instanceKey, stateAll[instanceKey][stateName]];
283
+ });
284
+ }
285
+
266
286
  function createUsePropAll(storeRegistry) {
267
287
  return function usePropAll(stateLink, instanceKeys) {
268
288
  const stateLinkRef = React.useRef({ stateLink });
@@ -279,23 +299,7 @@ function createUsePropAll(storeRegistry) {
279
299
  return internalStore.getStateAll();
280
300
  }, [internalStore]);
281
301
  const selector = React.useCallback((stateAll) => {
282
- let actualInstanceKeys;
283
- if (instanceKeys == null) {
284
- actualInstanceKeys = [...Object.keys(stateAll), ...Object.getOwnPropertySymbols(stateAll)];
285
- }
286
- else if (typeof instanceKeys === `function`) {
287
- actualInstanceKeys = [...Object.keys(stateAll), ...Object.getOwnPropertySymbols(stateAll)].filter((instanceKey) => {
288
- return instanceKeys(stateAll[instanceKey]);
289
- });
290
- }
291
- else {
292
- actualInstanceKeys = instanceKeys.filter((instanceKey) => {
293
- return instanceKey in stateAll;
294
- });
295
- }
296
- return actualInstanceKeys.map((instanceKey) => {
297
- return [instanceKey, stateAll[instanceKey][actualStateLink.stateName]];
298
- });
302
+ return pickPropAll(stateAll, actualStateLink.stateName, instanceKeys);
299
303
  }, [actualStateLink, instanceKeys]);
300
304
  return withSelector.useSyncExternalStoreWithSelector(subscribe, getSnapshot, null, selector, isEqual);
301
305
  };
@@ -311,6 +315,52 @@ function isEqual(prevStateAll, stateAll) {
311
315
  }
312
316
  }
313
317
 
318
+ function createUsePropSelector(storeRegistry) {
319
+ return function usePropSelector(stateLink, instanceKey) {
320
+ const stateLinkRef = React.useRef({ stateLink });
321
+ if (stateLinkRef.current.stateLink !== stateLink) {
322
+ console.warn(`State link reference mismatch. You must pass the same state link on every render.`);
323
+ }
324
+ const actualStateLink = stateLinkRef.current.stateLink;
325
+ const internalStoreProps = actualStateLink[INTERNAL_STORE_PROPS_ACCESSOR];
326
+ const storeContextValue = React.useContext(internalStoreProps.context);
327
+ const actualInstanceKey = instanceKey ?? storeContextValue?.instanceKey ?? DEFAULT_INSTANCE_KEY;
328
+ const internalStore = ensureInternalStore(storeRegistry, internalStoreProps);
329
+ const uninitializedState = storeContextValue?.instanceKey === actualInstanceKey
330
+ ? storeContextValue.uninitializedState
331
+ : internalStoreProps.initialState;
332
+ return React.useCallback(() => {
333
+ if (actualStateLink.stateName === INITIALIZED_STATE_NAME) {
334
+ return internalStore.isInitialized(actualInstanceKey);
335
+ }
336
+ else if (actualStateLink.stateName === INSTANCE_KEY_STATE_NAME) {
337
+ return actualInstanceKey;
338
+ }
339
+ else if (internalStore.isInitialized(actualInstanceKey)) {
340
+ return internalStore.getState(actualInstanceKey)[actualStateLink.stateName];
341
+ }
342
+ else {
343
+ return uninitializedState[actualStateLink.stateName];
344
+ }
345
+ }, [actualInstanceKey, actualStateLink, internalStore, uninitializedState]);
346
+ };
347
+ }
348
+
349
+ function createUsePropSelectorAll(storeRegistry) {
350
+ return function usePropSelectorAll(stateLink, instanceKeys) {
351
+ const stateLinkRef = React.useRef({ stateLink });
352
+ if (stateLinkRef.current.stateLink !== stateLink) {
353
+ console.warn(`State link reference mismatch. You must pass the same state link on every render.`);
354
+ }
355
+ const actualStateLink = stateLinkRef.current.stateLink;
356
+ const internalStoreProps = actualStateLink[INTERNAL_STORE_PROPS_ACCESSOR];
357
+ const internalStore = ensureInternalStore(storeRegistry, internalStoreProps);
358
+ return React.useCallback(() => {
359
+ return pickPropAll(internalStore.getStateAll(), actualStateLink.stateName, instanceKeys);
360
+ }, [actualStateLink, instanceKeys, internalStore]);
361
+ };
362
+ }
363
+
314
364
  function createUseStore(storeRegistry) {
315
365
  function useStore(store, ...args) {
316
366
  const storeRef = React.useRef({ store });
@@ -395,17 +445,21 @@ function createStoreRegistry() {
395
445
  const useStore = createUseStore(storeRegistry);
396
446
  const useProp = createUseProp(storeRegistry);
397
447
  const usePropAll = createUsePropAll(storeRegistry);
448
+ const usePropSelector = createUsePropSelector(storeRegistry);
449
+ const usePropSelectorAll = createUsePropSelectorAll(storeRegistry);
398
450
  const useDispatcher = createUseDispatcher(storeRegistry);
399
451
  const useLatest = createUseLatest();
400
452
  const StoreProvider = createStoreProvider(useStore);
401
453
  return {
402
- storeRegistry,
403
454
  StoreProvider,
404
- useStore,
405
- useProp,
406
- usePropAll,
455
+ storeRegistry,
407
456
  useDispatcher,
408
457
  useLatest,
458
+ useProp,
459
+ usePropAll,
460
+ usePropSelector,
461
+ usePropSelectorAll,
462
+ useStore,
409
463
  };
410
464
  }
411
465
 
@@ -536,7 +590,7 @@ const requestState = {
536
590
  },
537
591
  };
538
592
 
539
- const { StoreProvider, useDispatcher, useProp, usePropAll, useStore, } = createStoreRegistry();
593
+ const { StoreProvider, useDispatcher, useProp, usePropAll, usePropSelector, usePropSelectorAll, useStore, } = createStoreRegistry();
540
594
 
541
595
  exports.DESTROY = DESTROY;
542
596
  exports.InternalStore = InternalStore;
@@ -548,4 +602,6 @@ exports.requestStatus = requestStatus;
548
602
  exports.useDispatcher = useDispatcher;
549
603
  exports.useProp = useProp;
550
604
  exports.usePropAll = usePropAll;
605
+ exports.usePropSelector = usePropSelector;
606
+ exports.usePropSelectorAll = usePropSelectorAll;
551
607
  exports.useStore = useStore;
@@ -261,6 +261,26 @@ function createUseProp(storeRegistry) {
261
261
  };
262
262
  }
263
263
 
264
+ function pickPropAll(stateAll, stateName, instanceKeys) {
265
+ let actualInstanceKeys;
266
+ if (instanceKeys == null) {
267
+ actualInstanceKeys = [...Object.keys(stateAll), ...Object.getOwnPropertySymbols(stateAll)];
268
+ }
269
+ else if (typeof instanceKeys === `function`) {
270
+ actualInstanceKeys = [...Object.keys(stateAll), ...Object.getOwnPropertySymbols(stateAll)].filter((instanceKey) => {
271
+ return instanceKeys(stateAll[instanceKey]);
272
+ });
273
+ }
274
+ else {
275
+ actualInstanceKeys = instanceKeys.filter((instanceKey) => {
276
+ return instanceKey in stateAll;
277
+ });
278
+ }
279
+ return actualInstanceKeys.map((instanceKey) => {
280
+ return [instanceKey, stateAll[instanceKey][stateName]];
281
+ });
282
+ }
283
+
264
284
  function createUsePropAll(storeRegistry) {
265
285
  return function usePropAll(stateLink, instanceKeys) {
266
286
  const stateLinkRef = useRef({ stateLink });
@@ -277,23 +297,7 @@ function createUsePropAll(storeRegistry) {
277
297
  return internalStore.getStateAll();
278
298
  }, [internalStore]);
279
299
  const selector = useCallback((stateAll) => {
280
- let actualInstanceKeys;
281
- if (instanceKeys == null) {
282
- actualInstanceKeys = [...Object.keys(stateAll), ...Object.getOwnPropertySymbols(stateAll)];
283
- }
284
- else if (typeof instanceKeys === `function`) {
285
- actualInstanceKeys = [...Object.keys(stateAll), ...Object.getOwnPropertySymbols(stateAll)].filter((instanceKey) => {
286
- return instanceKeys(stateAll[instanceKey]);
287
- });
288
- }
289
- else {
290
- actualInstanceKeys = instanceKeys.filter((instanceKey) => {
291
- return instanceKey in stateAll;
292
- });
293
- }
294
- return actualInstanceKeys.map((instanceKey) => {
295
- return [instanceKey, stateAll[instanceKey][actualStateLink.stateName]];
296
- });
300
+ return pickPropAll(stateAll, actualStateLink.stateName, instanceKeys);
297
301
  }, [actualStateLink, instanceKeys]);
298
302
  return useSyncExternalStoreWithSelector(subscribe, getSnapshot, null, selector, isEqual);
299
303
  };
@@ -309,6 +313,52 @@ function isEqual(prevStateAll, stateAll) {
309
313
  }
310
314
  }
311
315
 
316
+ function createUsePropSelector(storeRegistry) {
317
+ return function usePropSelector(stateLink, instanceKey) {
318
+ const stateLinkRef = useRef({ stateLink });
319
+ if (stateLinkRef.current.stateLink !== stateLink) {
320
+ console.warn(`State link reference mismatch. You must pass the same state link on every render.`);
321
+ }
322
+ const actualStateLink = stateLinkRef.current.stateLink;
323
+ const internalStoreProps = actualStateLink[INTERNAL_STORE_PROPS_ACCESSOR];
324
+ const storeContextValue = useContext(internalStoreProps.context);
325
+ const actualInstanceKey = instanceKey ?? storeContextValue?.instanceKey ?? DEFAULT_INSTANCE_KEY;
326
+ const internalStore = ensureInternalStore(storeRegistry, internalStoreProps);
327
+ const uninitializedState = storeContextValue?.instanceKey === actualInstanceKey
328
+ ? storeContextValue.uninitializedState
329
+ : internalStoreProps.initialState;
330
+ return useCallback(() => {
331
+ if (actualStateLink.stateName === INITIALIZED_STATE_NAME) {
332
+ return internalStore.isInitialized(actualInstanceKey);
333
+ }
334
+ else if (actualStateLink.stateName === INSTANCE_KEY_STATE_NAME) {
335
+ return actualInstanceKey;
336
+ }
337
+ else if (internalStore.isInitialized(actualInstanceKey)) {
338
+ return internalStore.getState(actualInstanceKey)[actualStateLink.stateName];
339
+ }
340
+ else {
341
+ return uninitializedState[actualStateLink.stateName];
342
+ }
343
+ }, [actualInstanceKey, actualStateLink, internalStore, uninitializedState]);
344
+ };
345
+ }
346
+
347
+ function createUsePropSelectorAll(storeRegistry) {
348
+ return function usePropSelectorAll(stateLink, instanceKeys) {
349
+ const stateLinkRef = useRef({ stateLink });
350
+ if (stateLinkRef.current.stateLink !== stateLink) {
351
+ console.warn(`State link reference mismatch. You must pass the same state link on every render.`);
352
+ }
353
+ const actualStateLink = stateLinkRef.current.stateLink;
354
+ const internalStoreProps = actualStateLink[INTERNAL_STORE_PROPS_ACCESSOR];
355
+ const internalStore = ensureInternalStore(storeRegistry, internalStoreProps);
356
+ return useCallback(() => {
357
+ return pickPropAll(internalStore.getStateAll(), actualStateLink.stateName, instanceKeys);
358
+ }, [actualStateLink, instanceKeys, internalStore]);
359
+ };
360
+ }
361
+
312
362
  function createUseStore(storeRegistry) {
313
363
  function useStore(store, ...args) {
314
364
  const storeRef = useRef({ store });
@@ -393,17 +443,21 @@ function createStoreRegistry() {
393
443
  const useStore = createUseStore(storeRegistry);
394
444
  const useProp = createUseProp(storeRegistry);
395
445
  const usePropAll = createUsePropAll(storeRegistry);
446
+ const usePropSelector = createUsePropSelector(storeRegistry);
447
+ const usePropSelectorAll = createUsePropSelectorAll(storeRegistry);
396
448
  const useDispatcher = createUseDispatcher(storeRegistry);
397
449
  const useLatest = createUseLatest();
398
450
  const StoreProvider = createStoreProvider(useStore);
399
451
  return {
400
- storeRegistry,
401
452
  StoreProvider,
402
- useStore,
403
- useProp,
404
- usePropAll,
453
+ storeRegistry,
405
454
  useDispatcher,
406
455
  useLatest,
456
+ useProp,
457
+ usePropAll,
458
+ usePropSelector,
459
+ usePropSelectorAll,
460
+ useStore,
407
461
  };
408
462
  }
409
463
 
@@ -534,6 +588,6 @@ const requestState = {
534
588
  },
535
589
  };
536
590
 
537
- const { StoreProvider, useDispatcher, useProp, usePropAll, useStore, } = createStoreRegistry();
591
+ const { StoreProvider, useDispatcher, useProp, usePropAll, usePropSelector, usePropSelectorAll, useStore, } = createStoreRegistry();
538
592
 
539
- export { DESTROY, InternalStore, StoreProvider, createStore, createStoreRegistry, requestState, requestStatus, useDispatcher, useProp, usePropAll, useStore };
593
+ export { DESTROY, InternalStore, StoreProvider, createStore, createStoreRegistry, requestState, requestStatus, useDispatcher, useProp, usePropAll, usePropSelector, usePropSelectorAll, useStore };
package/package.json CHANGED
@@ -20,5 +20,5 @@
20
20
  "prepublishOnly": "npm run build"
21
21
  },
22
22
  "types": "dist/@types",
23
- "version": "0.1.11"
23
+ "version": "0.1.12"
24
24
  }
@@ -1 +0,0 @@
1
- export declare function createUseSelector(): any;