@@ -14,16 +14,30 @@ import {
1414} from './useBaseAgile' ;
1515import { AgileValueHookType } from './useValue' ;
1616
17+ /**
18+ * A React Hook for binding a selected value of an Agile Instance
19+ * (like the Collection's output or the State's value)
20+ * to a React Functional Component.
21+ *
22+ * This binding ensures that the Component re-renders
23+ * whenever the selected value of an Agile Instance mutates.
24+ *
25+ * @public
26+ * @param dep - Agile Sub Instance to be bound to the Functional Component.
27+ * @param selectorMethod - Equality comparison function.
28+ * that allows you to customize the way the selected Agile Instance
29+ * is compared to determine whether the Component needs to be re-rendered.
30+ * @param config - Configuration object
31+ */
1732export function useSelector <
1833 ReturnType ,
1934 X extends SubscribableAgileInstancesType ,
2035 ValueType extends AgileValueHookType < X >
2136> (
2237 dep : X ,
23- selector : SelectorMethodType < ValueType > ,
38+ selectorMethod : SelectorMethodType < ValueType > ,
2439 config ?: BaseAgileHookConfigInterface
2540) : ReturnType ;
26-
2741/**
2842 * A React Hook for binding a selected value of an Agile Instance
2943 * (like the Collection's output or the State's value)
@@ -34,14 +48,14 @@ export function useSelector<
3448 *
3549 * @public
3650 * @param dep - Agile Sub Instance to be bound to the Functional Component.
37- * @param selector - Equality comparison function
51+ * @param selectorMethod - Equality comparison function.
3852 * that allows you to customize the way the selected Agile Instance
3953 * is compared to determine whether the Component needs to be re-rendered.
4054 * @param config - Configuration object
4155 */
4256export function useSelector < ValueType = any , ReturnType = any > (
4357 dep : SubscribableAgileInstancesType ,
44- selector : SelectorMethodType < ValueType > ,
58+ selectorMethod : SelectorMethodType < ValueType > ,
4559 config ?: BaseAgileHookConfigInterface
4660) : ReturnType ;
4761
@@ -51,13 +65,14 @@ export function useSelector<
5165 ReturnType = any
5266> (
5367 dep : X ,
54- selector : SelectorMethodType < ValueType > ,
68+ selectorMethod : SelectorMethodType < ValueType > ,
5569 config : BaseAgileHookConfigInterface = { }
5670) : ReturnType {
5771 config = defineConfig ( config , {
5872 key : generateId ( ) ,
5973 agileInstance : null as any ,
6074 componentId : undefined ,
75+ deps : [ ] ,
6176 } ) ;
6277 const depsArray = extractRelevantObservers ( [ dep ] ) ;
6378
@@ -70,7 +85,7 @@ export function useSelector<
7085 // (Destroys the type of the useAgile hook,
7186 // however the type can be adjusted in the useSelector hook)
7287 if ( isValidObject ( value , true ) ) {
73- return selector ( value ) ;
88+ return selectorMethod ( value ) ;
7489 }
7590
7691 return value ;
@@ -83,7 +98,7 @@ export function useSelector<
8398 let selectorWeakMap : SelectorWeakMapType | undefined = undefined ;
8499 selectorWeakMap = new WeakMap ( ) ;
85100 for ( const observer of observers ) {
86- selectorWeakMap . set ( observer , { methods : [ selector ] } ) ;
101+ selectorWeakMap . set ( observer , { methods : [ selectorMethod ] } ) ;
87102 }
88103
89104 return {
0 commit comments