Skip to content

Commit 7cc72f0

Browse files
committed
fix: run detectChanges after set
1 parent 6f2e12f commit 7cc72f0

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeDetectorRef, Injectable } from '@angular/core';
1+
import { ChangeDetectorRef, inject, Injectable } from '@angular/core';
22
import { RxState } from '@rx-angular/state';
33
import { combineLatest, MonoTypeOperatorFunction, Observable, startWith, tap } from 'rxjs';
44
import type { NgtAnyRecord } from '../types';
@@ -76,6 +76,7 @@ export class NgtRxStore<
7676
> extends RxState<TRxState> {
7777
constructor() {
7878
super();
79+
const cdr = inject(ChangeDetectorRef, { optional: true });
7980
// set a dummy property so that initial this.get() won't return undefined
8081
this.set({ __ngt_dummy__: '__ngt_dummy__' } as TRxState);
8182
// call initialize that might be setup by derived Stores
@@ -92,10 +93,14 @@ export class NgtRxStore<
9293
modded[key] = value === undefined ? this.get(key as keyof TRxState) : value;
9394
return modded;
9495
}, {} as NgtAnyRecord);
95-
return originalSet(modArgs as Partial<TRxState>);
96+
const value = originalSet(modArgs as Partial<TRxState>);
97+
cdr?.detectChanges();
98+
return value;
9699
}
97100
// @ts-expect-error not sure why ...args here doesn't pass tuple check
98-
return originalSet(...args);
101+
const value = originalSet(...args);
102+
cdr?.detectChanges();
103+
return value;
99104
};
100105
},
101106
});

0 commit comments

Comments
 (0)