Replies: 1 comment
-
You can create an effect in your ComponentStore. Below is an example. Note: class ChartDynamicCompanyCountStore extends ComponentStore<State> {
private readonly authStore = inject(AuthStore);
loadChartData = this.effect(() => {
const companyIdChange$ = toObservable(authStore.companyId);
return companyIdChange$.pipe(
tap(companyId => {
const request: DynamicCompanyCountRequest = {
name: "CompanyCount",
startDate: DateFormatting.fromDateTimeToString(
this.startDate(),
),
endDate: DateFormatting.fromDateTimeToString(this.endDate()),
};
this.load(request);
})
);
});
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have what seems to be a simple scenario where I have a global store AuthStore that contains a signal for the current selected CompanyId which can be switched by the user via the UI at any given point. I then have a chart component that needs to refresh it's data if the CompanyId signal changes via a rxMethod method that makes a HTTP request to retrieve the new data.
The only solution I've found is to convert my signal to an Observable and subscribe to it as shown below. However, I was hoping that subscribing and unsubscribing in my components might become a thing of the past.
When the user changes the company I need to refresh the chart data by calling loadChartData, this was all perfectly feasible using the Redux pattern with @ngrx/store via side effects, actions and reducers. Have I missed something or is my design just simply not conducive to this approach?
Beta Was this translation helpful? Give feedback.
All reactions