@@ -11,25 +11,31 @@ const refEquality: EqualityFn<any> = (a, b) => a === b
1111// TODO: Add support for `withTypes`
1212export function injectSelector < TState = unknown , Selected = unknown > (
1313 selector : ( state : TState ) => Selected ,
14- equalityFnOrOptions ? : EqualityFn < Selected > | UseSelectorOptions < Selected > ,
14+ equalityFnOrOptions : EqualityFn < Selected > | UseSelectorOptions < Selected > = { } ,
1515) : Signal < Selected > {
1616 assertInInjectionContext ( injectSelector )
1717 const reduxContext = inject ( ReduxProvider ) ;
1818
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
2323
2424 const {
25- store
25+ store,
26+ subscription
2627 } = reduxContext
2728
2829 const selectedState = signal ( selector ( store . getState ( ) ) )
2930
3031 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 ) ;
3339 } )
3440
3541 onCleanup ( ( ) => {
0 commit comments