@@ -11,25 +11,31 @@ const refEquality: EqualityFn<any> = (a, b) => a === b
11
11
// TODO: Add support for `withTypes`
12
12
export function injectSelector < TState = unknown , Selected = unknown > (
13
13
selector : ( state : TState ) => Selected ,
14
- equalityFnOrOptions ? : EqualityFn < Selected > | UseSelectorOptions < Selected > ,
14
+ equalityFnOrOptions : EqualityFn < Selected > | UseSelectorOptions < Selected > = { } ,
15
15
) : Signal < Selected > {
16
16
assertInInjectionContext ( injectSelector )
17
17
const reduxContext = inject ( ReduxProvider ) ;
18
18
19
- // const { equalityFn = refEquality } =
20
- // typeof equalityFnOrOptions === 'function'
21
- // ? { equalityFn: equalityFnOrOptions }
22
- // : equalityFnOrOptions
19
+ const { equalityFn = refEquality } =
20
+ typeof equalityFnOrOptions === 'function'
21
+ ? { equalityFn : equalityFnOrOptions }
22
+ : equalityFnOrOptions
23
23
24
24
const {
25
- store
25
+ store,
26
+ subscription
26
27
} = reduxContext
27
28
28
29
const selectedState = signal ( selector ( store . getState ( ) ) )
29
30
30
31
effect ( ( onCleanup ) => {
31
- const unsubscribe = store . subscribe ( ( ) => {
32
- selectedState . set ( selector ( store . getState ( ) ) )
32
+ const unsubscribe = subscription . addNestedSub ( ( ) => {
33
+ const data = selector ( store . getState ( ) ) ;
34
+ if ( equalityFn ( selectedState ( ) , data ) ) {
35
+ return
36
+ }
37
+
38
+ selectedState . set ( data ) ;
33
39
} )
34
40
35
41
onCleanup ( ( ) => {
0 commit comments