-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(store): support meta reducer factory for feature (#1414) #1445
feat(store): support meta reducer factory for feature (#1414) #1445
Conversation
Preview docs changes for a51d037 at https://previews.ngrx.io/pr1445-a51d037/ |
please let me know if you like the solution... A code example of how to use this feature:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the implementation is good and should solve the issue you've encountered.
What are your thoughts about this @brandonroberts , should we go further with this?
This change should be backward compatible with the option to override the metaReducers
option config, by using an injection token.
a51d037
to
d6f7348
Compare
Preview docs changes for d6f7348 at https://previews.ngrx.io/pr1445-d6f7348/ |
@timdeschryver I think if we're going to allow an injection token, it should at the configuration level and not the meta-reducer level. It would prevent us from having an injection token for each thing you want to configure using DI. |
Having that said, But of course it is for you to decide rather you like the idea or not. |
So to clear, you mean something like this? export function _createFeatureStore(
injector: Injector,
configs: StoreFeature<any, any>[]
) {
return configs.map(config => {
return config instanceof InjectionToken ? {...config, ...injector.get(config)} : config;
)}
} |
Yes, something like that. You wouldn't spread the config if its an InjectionToken though since it contains the entire feature object. We also need some tests to verify this correctly merges configs from different NgModules, including lazy loaded ones. |
so the api will look something like that? export const MY_FEATURE_CONFIG_TOKEN = new InjectionToken('Feature Config');
...
StoreModule.forFeature('feature', {}, MY_FEATURE_CONFIG_TOKEN), |
Yes |
4254066
to
3d8b50c
Compare
I have made some changes in another commit (just in case...) |
Its getting there. I'd prefer to keep There also needs to be a test that provides an injection token for a feature config. |
I see, I think that if we must support multi provider for @brandonroberts @timdeschryver please let me know what do think, or if you have some other solutions, I will be happy to implement them :) |
I think the implementation is good, just a few details:
export function _createFeatureStore(injector: Injector, features: Array<any>) {
return features.map(feat => {
if(feat.config instanceof InjectionToken) {
const config = injector.get(feat.config);
return {
key: feat.key,
reducerFactory: config.reducerFactory,
metaReducers: config.metaReducers,
initialState: config.initialState
}
}
return {
key: feat.key,
reducerFactory: feat.config.reducerFactory
? feat.config.reducerFactory
: combineReducers,
metaReducers: feat.config.metaReducers ? feat.config.metaReducers : [],
initialState: feat.config.initialState,
};
});
}
|
There are a couple of options I see that we can do here.
|
@brandonroberts I see, the first option could work, I will try implement it and make another commit. |
061a421
to
4f7669a
Compare
@itayod is this ready? Will you rebase on master? |
almost, just wanted to make few code improvements that @timdeschryver advised me and I think we are good to go :) |
4f7669a
to
a6a5629
Compare
Preview docs changes for a6a5629 at https://previews.ngrx.io/pr1445-a6a5629/ |
@brandonroberts @timdeschryver have you seen my update? think we can close that now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the implementation is good, the comments are mostly for the created tests.
Wait until @brandonroberts approves the implementation, otherwise, chances are you would have changed these tests for nothing.
@brandonroberts @timdeschryver have you seen my last commit? |
f7cd4fb
to
3f078cb
Compare
Preview docs changes for f7cd4fb at https://previews.ngrx.io/pr1445-f7cd4fb/ |
Preview docs changes for 3f078cb at https://previews.ngrx.io/pr1445-3f078cb/ |
Couple more changes and we should be good to go. |
3f078cb
to
32fc4a6
Compare
done :) |
Preview docs changes for 32fc4a6 at https://previews.ngrx.io/pr1445-32fc4a6/ |
@timdeschryver you have anymore feedback on this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just some few nits.
Also, while testing this I encountered the following:
-
The user has to define the
reducerFactory
if she uses an injection token. We can leave it as is now, but I think 99% of the cases are using the defaultcombineReducers
. Should we fall back tocombineReducers
, if the user doesn't specify thereducerFactory
(just like inforFeature
)? We can leave it for now and see how it goes. -
If we provide a meta-reducer and an initial state (via
forFeature
, or via an injection token) - the initial state gets "lost". I think this is a bug.
The |
👍 I'll take a look at the issues, if it isn't filed - I will create a new issue. In advance, a happy new year 🎉 ! |
happy new year!! I will make another commit with the required changes right away :) about the initial state bug... if you would like, I am available to try solving it and make another pr. |
84cf8f5
to
fedb68d
Compare
fedb68d
to
37e4f69
Compare
Preview docs changes for 84cf8f5 at https://previews.ngrx.io/pr1445-84cf8f5/ |
Preview docs changes for 37e4f69 at https://previews.ngrx.io/pr1445-37e4f69/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Preview docs changes for 6c801b1 at https://previews.ngrx.io/pr1445-6c801b1/ |
@itayod keep the fix for the initial state in a separate PR so we can merge this one on its own. |
@brandonroberts |
6c801b1
to
37e4f69
Compare
🎉 |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Closes #1414
What is the new behavior?
Does this PR introduce a breaking change?
Other information