Skip to content
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

[feature] provide FeatureStore #106

Closed
amitport opened this issue Jul 19, 2017 · 2 comments
Closed

[feature] provide FeatureStore #106

amitport opened this issue Jul 19, 2017 · 2 comments

Comments

@amitport
Copy link
Contributor

Currently we can declare reducers in module hierarchy. We still always provide the root Store though. It would be nice if we could further separate individual modules, allowing them to request only the innermost FeatureStore (which is a view of the store for a specific feature).

(ngrx is great BTW)

@amitport
Copy link
Contributor Author

The current way I'm doing this

const ROOT_STORE = new InjectionToken<Store<MyAppState>>('rootStore');

in root module:
{provide: ROOT_STORE, useExisting: Store}

in child module:
{ provide: Store, useFactory: (store: Store<MyAppState>) => store.select(createFeatureSelector<MyFeatureState>('myFeature')), deps: [ROOT_STORE] }

(we refer to MyAppState and ROOT_STORE in child module for type safety, but could skip this and use string as a type token if we want complete separation)

@MikeRyanDev
Copy link
Member

MikeRyanDev commented Jul 19, 2017

Your solution is how we would recommend going about this. We thought long and hard about whether or not we should scope instances of Store to feature state and ultimately came to the conclusion that - while powerful - it can be very confusing to track what instances of Store are received by which components. It also complicates deriving state from multiple features, a pattern that is common in our own applications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants