You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working now for some years with ngrx and nowadays I always get the same problem in the applications. My applications are kinda big and have multiple feature stores.
Let's take for an example a LanguageFeature and a TodoFeature. The TodoFeature holds all open todos. The todos are translated and depend on the language. It has the typical 3 actions loadTodos, loadTodosSuccess and loadTodosError.
In a ListComponent I trigger the loadTodos. An effect catches this action and loads the todos and responds with a loadTodosSuccess or loadTodosError accordingly. So far so good. The dependency on the language can be handled differently in multiple decisions:
Decision 1
Does the loadTodos action have a language parameter? ('Load Todos': props<{language: string;}>())
You can load it in the component and provide it to the action with selectLanguage
language = this.store.selectSignal(selectLanguage)
this.store.dispatch(TodosActions.loadTodos({language})
Nowadays I go mostly for the 2. option, because it reduces the logic in the component and most of the times the component just loads stuff from the store just to add it again to the dispatch to the store, which already knows this stuff.
The only drawback I see with the 2. option are:
the direct dependency of the Todos to the language
The lifecycle of the reloading is outside of the component so it can get hard to stop the cycle of reloading the todos when the language changes. Because if the application grows it can cause a lot of reloads at once that aren't needed at the moment.
But I would like to have your opinion on it. Are you doing it similar? Because I'm not quite happy with every solution
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm working now for some years with ngrx and nowadays I always get the same problem in the applications. My applications are kinda big and have multiple feature stores.
Let's take for an example a LanguageFeature and a TodoFeature. The TodoFeature holds all open todos. The todos are translated and depend on the language. It has the typical 3 actions
loadTodos
,loadTodosSuccess
andloadTodosError
.In a ListComponent I trigger the
loadTodos
. An effect catches this action and loads the todos and responds with a loadTodosSuccess or loadTodosError accordingly. So far so good. The dependency on the language can be handled differently in multiple decisions:Decision 1
Does the loadTodos action have a language parameter? (
'Load Todos': props<{language: string;}>()
)Nowadays I decide this decision if the value could be different. If yes I go with the 1. Version otherwise I go with the 2. version.
Decision 2
How to reload the todos when the language changes?
LanguageChanged
-Action to theLoadTodosAction
in the Todos-Effects to (Todos depends on Language)LanguageChanged
-Action to theLoadTodosAction
in the Language-Effects (Language depends on Todos)Nowadays I go mostly for the 2. option, because it reduces the logic in the component and most of the times the component just loads stuff from the store just to add it again to the dispatch to the store, which already knows this stuff.
The only drawback I see with the 2. option are:
But I would like to have your opinion on it. Are you doing it similar? Because I'm not quite happy with every solution
Beta Was this translation helpful? Give feedback.
All reactions