Skip to content

Commit f2a2212

Browse files
fix(component-store): export EffectReturnFn interface (#2555)
1 parent d7958e7 commit f2a2212

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

modules/component-store/src/component-store.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { debounceSync } from './debounceSync';
2222
* Return type of the effect, that behaves differently based on whether the
2323
* argument is passed to the callback.
2424
*/
25-
interface EffectReturnFn<T> {
25+
export interface EffectReturnFn<T> {
2626
(): void;
2727
(t: T | Observable<T>): Subscription;
2828
}
@@ -36,7 +36,7 @@ export class ComponentStore<T extends object> {
3636
private readonly stateSubject$ = new ReplaySubject<T>(1);
3737
private isInitialized = false;
3838
// Needs to be after destroy$ is declared because it's used in select.
39-
readonly state$: Observable<T> = this.select(s => s);
39+
readonly state$: Observable<T> = this.select((s) => s);
4040

4141
constructor(defaultState?: T) {
4242
// State can be initialized either through constructor, or initState or
@@ -80,22 +80,21 @@ export class ComponentStore<T extends object> {
8080
: of(observableOrValue);
8181
const subscription = observable$
8282
.pipe(
83-
concatMap(
84-
value =>
85-
this.isInitialized
86-
? of(value).pipe(withLatestFrom(this.stateSubject$))
87-
: // If state was not initialized, we'll throw an error.
88-
throwError(
89-
Error(`${this.constructor.name} has not been initialized`)
90-
)
83+
concatMap((value) =>
84+
this.isInitialized
85+
? of(value).pipe(withLatestFrom(this.stateSubject$))
86+
: // If state was not initialized, we'll throw an error.
87+
throwError(
88+
Error(`${this.constructor.name} has not been initialized`)
89+
)
9190
),
9291
takeUntil(this.destroy$)
9392
)
9493
.subscribe({
9594
next: ([value, currentState]) => {
9695
this.stateSubject$.next(updaterFn(currentState, value!));
9796
},
98-
error: error => {
97+
error: (error) => {
9998
initializationError = error;
10099
this.stateSubject$.error(error);
101100
},
@@ -211,7 +210,7 @@ export class ComponentStore<T extends object> {
211210
const observable$ = isObservable(observableOrValue)
212211
? observableOrValue
213212
: of(observableOrValue);
214-
return observable$.pipe(takeUntil(this.destroy$)).subscribe(value => {
213+
return observable$.pipe(takeUntil(this.destroy$)).subscribe((value) => {
215214
// any new 👇 value is pushed into a stream
216215
origin$.next(value);
217216
});

0 commit comments

Comments
 (0)