@@ -8,8 +8,12 @@ import {
88 linkedSignal ,
99 runInInjectionContext
1010} from '@angular/core' ;
11- import type { CreateSignalOptions , Signal } from '@angular/core' ;
12- import { shallowEqual , type Readable } from '@xstate/store' ;
11+ import type { Signal } from '@angular/core' ;
12+ import { type Readable } from '@xstate/store' ;
13+
14+ function defaultCompare < T > ( a : T , b : T ) {
15+ return a === b ;
16+ }
1317
1418/**
1519 * An Angular function that creates a signal subscribed to a store, selecting a
@@ -34,32 +38,28 @@ import { shallowEqual, type Readable } from '@xstate/store';
3438 * @param store The store, created from `createStore(…)`
3539 * @param selector A function which takes in the snapshot and returns a selected
3640 * value
37- * @param options Optional signal creation options with compare function and
38- * injector
41+ * @param compare An optional function which compares the selected value to the
42+ * previous value
3943 * @returns A readonly Signal of the selected value
4044 */
4145export function injectStore < TStore extends Readable < any > , TSelected > (
4246 store : TStore ,
4347 selector ?: ( state : TStore extends Readable < infer T > ? T : never ) => TSelected ,
44- options ?: CreateSignalOptions < TSelected > & { injector ?: Injector }
48+ compare ?: ( a : TSelected , b : TSelected ) => boolean
4549) : Signal < TSelected > ;
4650export function injectStore < TStore extends Readable < any > , TSelected > (
4751 store : TStore ,
4852 selector : (
4953 state : TStore extends Readable < infer T > ? T : never
5054 ) => TSelected = ( d ) => d as TSelected ,
51- options : CreateSignalOptions < TSelected > & { injector ?: Injector } = {
52- equal : shallowEqual
53- }
55+ compare : ( a : TSelected , b : TSelected ) => boolean = defaultCompare
5456) : Signal < TSelected > {
55- if ( ! options . injector ) {
56- assertInInjectionContext ( injectStore ) ;
57- options . injector = inject ( Injector ) ;
58- }
57+ assertInInjectionContext ( injectStore ) ;
58+ const injector = inject ( Injector ) ;
5959
60- return runInInjectionContext ( options . injector , ( ) => {
60+ return runInInjectionContext ( injector , ( ) => {
6161 const destroyRef = inject ( DestroyRef ) ;
62- const slice = linkedSignal ( ( ) => selector ( store . get ( ) ) , options ) ;
62+ const slice = linkedSignal ( ( ) => selector ( store . get ( ) ) , { equal : compare } ) ;
6363
6464 const { unsubscribe } = store . subscribe ( ( s ) => {
6565 slice . set ( selector ( s ) ) ;
0 commit comments