Skip to content

Commit b9d5ad4

Browse files
committed
fix: use safeDetectChanges instaed
1 parent 27e0dc6 commit b9d5ad4

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

libs/angular-three/src/lib/stores/rx-store.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { RxState } from '@rx-angular/state';
33
import { combineLatest, MonoTypeOperatorFunction, Observable, startWith, tap } from 'rxjs';
44
import type { NgtAnyRecord } from '../types';
55
import { is } from '../utils/is';
6+
import { safeDetectChanges } from '../utils/safe-detect-changes';
67

78
export const startWithUndefined = <T>(): MonoTypeOperatorFunction<T> => startWith<T>(undefined! as T);
89

@@ -94,12 +95,12 @@ export class NgtRxStore<
9495
return modded;
9596
}, {} as NgtAnyRecord);
9697
const value = originalSet(modArgs as Partial<TRxState>);
97-
cdr?.detectChanges();
98+
safeDetectChanges(cdr);
9899
return value;
99100
}
100101
// @ts-expect-error not sure why ...args here doesn't pass tuple check
101102
const value = originalSet(...args);
102-
cdr?.detectChanges();
103+
safeDetectChanges(cdr);
103104
return value;
104105
};
105106
},

libs/angular-three/src/lib/utils/safe-detect-changes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { ChangeDetectorRef } from '@angular/core';
22
import { NgtAnyRecord } from '../types';
33

4-
export function safeDetectChanges(cdr: ChangeDetectorRef) {
4+
export function safeDetectChanges(cdr: ChangeDetectorRef | null) {
5+
if (!cdr) return;
56
try {
67
if ((cdr as NgtAnyRecord)['context']) {
78
cdr.detectChanges();

0 commit comments

Comments
 (0)