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
{{ message }}
This repository has been archived by the owner on Jan 10, 2018. It is now read-only.
I have been reviewing a lot of videos and documentations to better understand ngrx. I am trying to use ngrx properly, which is the purpose of this question. I love the power you get with state separation and my use case definitely applies to this method.
This is my use case
My team uses Kendo's Grid to display almost all of our data. Because we use this grid throughout our app, we created a wrapper around it, to give it styling and created components that helped make it easier for the developer to use Kendo without worrying about styling. Before we knew about ngrx, we had a few services that handled selections, our data (from an API) and other parts of our state. The part that makes this complicated is that we have multiple types of grids that each have their own set of data, as well as their own grid. For example, we may have a list of properties that shows a grid, another grid that has a list of projects. So each will use the grid, but will work with different types of data. Our main goal is to limit the amount of code that the consuming developer has to do. Because of this constraint, each grid will need their own set of state, map to their own set of actions and reducers. This is the main reason I am struggling to understand how best to use ngrx.
The "best" way that I have found is to create a class that acts like a Factory, where it asks for the url and name of your store, then it will return the reducers, as well as the effects you need to get that grid working properly.
...
imports: [AppRoutingModule,CoreModule,TranslateModule.forRoot({provide: TranslateLoader,useClass: AppTranslateLoader,}),// Project Reducers and EffectsStoreModule.provideStore(ProjectReducerAndEffects.actionReducer),EffectsModule.run(ProjectReducerAndEffects.GridEffects),EffectsModule.run(ProjectReducerAndEffects.ApiEffects),EffectsModule.run(ProjectReducerAndEffects.GridSelectionEffects),EffectsModule.run(ProjectReducerAndEffects.SlideOutEffects),// Property Reducers and EffectsStoreModule.provideStore(PropertyReducerAndEffects.actionReducer),EffectsModule.run(PropertyReducerAndEffects.GridEffects),EffectsModule.run(PropertyReducerAndEffects.ApiEffects),EffectsModule.run(PropertyReducerAndEffects.GridSelectionEffects),EffectsModule.run(PropertyReducerAndEffects.SlideOutEffects),],
...
Critique of this method
Obviously, having a factory class that generates classes that act as services for angular is very odd and quite unusual. Honestly, I almost feel as though this is the way we will need to do it, so we have specific store names for each type of grid (whether it be for projects or properties, etc).
I understand that I didn't show all the other files that I have implemented to make this work. I did that for a reason. I am asking more for guidance about this approach rather than solving the errors I'm dealing with. If your guidance shows that this is the right way, then I will talk about the errors that I am getting in more depth.
Also, to see how this comes together with specific store names, here is an example of a reducer:
In this way, each reducer and action is specific to the store name, but still limits how much the developers need to do when they make their specified grid.
Any suggestions or ideas?
The text was updated successfully, but these errors were encountered:
This problem was easily resolved by passing in the store name and store url into the payload where it was needed. This way, there was no need to have this class that created Effect classes.
I've been trying to get a very similar solution working. This seems to be one of the more elegant ways of generalizing the actions, effects, reducers of ngrx/store. Did you end up getting this to work with the store url and name in the action payload in order to not generate the effects classes for each of your types in the store? If so, could you share that solution as I think it could apply to my own use case. Thanks!
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I have been reviewing a lot of videos and documentations to better understand
ngrx
. I am trying to usengrx
properly, which is the purpose of this question. I love the power you get with state separation and my use case definitely applies to this method.This is my use case
My team uses
Kendo's Grid
to display almost all of our data. Because we use this grid throughout our app, we created a wrapper around it, to give it styling and created components that helped make it easier for the developer to use Kendo without worrying about styling. Before we knew aboutngrx
, we had a few services that handled selections, our data (from an API) and other parts of our state. The part that makes this complicated is that we have multiple types of grids that each have their own set of data, as well as their own grid. For example, we may have a list of properties that shows a grid, another grid that has a list of projects. So each will use the grid, but will work with different types of data. Our main goal is to limit the amount of code that the consuming developer has to do. Because of this constraint, each grid will need their own set of state, map to their own set of actions and reducers. This is the main reason I am struggling to understand how best to usengrx
.The "best" way that I have found is to create a class that acts like a Factory, where it asks for the url and name of your store, then it will return the reducers, as well as the effects you need to get that grid working properly.
To show how one of the effects class, that is generic, work; here is the PrmApiEffects:
To show how the SlideOutActionReducer is made, here is the function:
Then, for our Property Grid, we would instantiate this class:
Same goes for the project grid
In our module, we would then do this:
Critique of this method
Obviously, having a factory class that generates classes that act as services for angular is very odd and quite unusual. Honestly, I almost feel as though this is the way we will need to do it, so we have specific store names for each type of grid (whether it be for projects or properties, etc).
I understand that I didn't show all the other files that I have implemented to make this work. I did that for a reason. I am asking more for guidance about this approach rather than solving the errors I'm dealing with. If your guidance shows that this is the right way, then I will talk about the errors that I am getting in more depth.
Also, to see how this comes together with specific store names, here is an example of a reducer:
And here is an example of our action:
This way, in our component, we simply do this:
In this way, each reducer and action is specific to the store name, but still limits how much the developers need to do when they make their specified grid.
Any suggestions or ideas?
The text was updated successfully, but these errors were encountered: