ngrx type of store when using feature modulengrx/store inject store into a functionAngular 2 Ngrx Store, Effects and “Ephemeral States”Using @ngrx/store in Angular 2 applicationstate management using ngrx/store and ngrx/effects in Angular 2NgRx can't select from storeAngular ngrx-store: How to share store among modules (main module / feature module)@ngrx/store combine multiple reducers from feature moduleHow to subscribe to changes in feature module in NgRx?ngrx: create reusable actions across several feature modulesNgRx shared store resets when loading lazy loaded module
50% portfolio in single stock, JPM - appropriate for 80 year old?
What are these criss-cross patterns close to Cambridge Airport (UK)?
Grep over multiple files redirecting to a different filename each time
Is there any point in adding more than 6 months' runway in savings instead of investing everything after that?
At what point in time would humans notice a 21st century satellite observing them?
Speaking German abroad and feeling condescended to when people speak English back to me
Would nuclear bombs be effective against clouds of nanites?
Why does modular exponentiation always form a cycle?
Why rounding odd font sizes to even?
Was there a clearly identifiable "first computer" to use or demonstrate the use of virtual memory?
Diophantine equation in Laurent polynomials
My name causes an issue with any booking! (names end with MR and MRS)
What does the 1.-5. notation mean at the top right corner?
Which act of Congress authorized the Ukrainian aid which was allegedly withheld?
Identify the Eeveelutions
How to communicate faster than the system clock
Can a vampire charm a blind person?
What are standard cryptographic assumptions?
Passport expiration requirement for Jordan Visa
When does Scandinavian Mountains Airport open?
Dissecting the exotic bulbfish
Why use [FormalN]?
Why are Democrats mostly focused on increasing healthcare spending, rarely mentioning any proposals for decreasing the costs of healthcare services?
Completing the square to solve limit problems
ngrx type of store when using feature module
ngrx/store inject store into a functionAngular 2 Ngrx Store, Effects and “Ephemeral States”Using @ngrx/store in Angular 2 applicationstate management using ngrx/store and ngrx/effects in Angular 2NgRx can't select from storeAngular ngrx-store: How to share store among modules (main module / feature module)@ngrx/store combine multiple reducers from feature moduleHow to subscribe to changes in feature module in NgRx?ngrx: create reusable actions across several feature modulesNgRx shared store resets when loading lazy loaded module
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
As I understand, if I am to use feature modules, I create a state slice for each feature:
StoreModule.forFeature('user', userReducer.reducer)
And in the root module I do an
StoreModule.forRoot()
Now when I want to use the store in my component I do is inject the store:
constructor( private store: Store<any>)
and
this.store.select(state => state.user.saveError)
.subscribe((error) =>
this.toastOptions.msg = error;
this.toastyService.error(this.toastOptions);
);
If all that is correct, what is the proper type of the store variable here?
angular ngrx
add a comment
|
As I understand, if I am to use feature modules, I create a state slice for each feature:
StoreModule.forFeature('user', userReducer.reducer)
And in the root module I do an
StoreModule.forRoot()
Now when I want to use the store in my component I do is inject the store:
constructor( private store: Store<any>)
and
this.store.select(state => state.user.saveError)
.subscribe((error) =>
this.toastOptions.msg = error;
this.toastyService.error(this.toastOptions);
);
If all that is correct, what is the proper type of the store variable here?
angular ngrx
basicallystore: Store<user: Object>
– Jota.Toledo
Mar 28 at 22:01
your class name which containsuser
&user.saveError
– Aravind
Mar 28 at 22:08
I would also add, spend some time looking using selectors: export const selectUserState = state => state.user as UserState; you can then used pipe(select(selectUserState))
– user9298624
Mar 28 at 23:32
add a comment
|
As I understand, if I am to use feature modules, I create a state slice for each feature:
StoreModule.forFeature('user', userReducer.reducer)
And in the root module I do an
StoreModule.forRoot()
Now when I want to use the store in my component I do is inject the store:
constructor( private store: Store<any>)
and
this.store.select(state => state.user.saveError)
.subscribe((error) =>
this.toastOptions.msg = error;
this.toastyService.error(this.toastOptions);
);
If all that is correct, what is the proper type of the store variable here?
angular ngrx
As I understand, if I am to use feature modules, I create a state slice for each feature:
StoreModule.forFeature('user', userReducer.reducer)
And in the root module I do an
StoreModule.forRoot()
Now when I want to use the store in my component I do is inject the store:
constructor( private store: Store<any>)
and
this.store.select(state => state.user.saveError)
.subscribe((error) =>
this.toastOptions.msg = error;
this.toastyService.error(this.toastOptions);
);
If all that is correct, what is the proper type of the store variable here?
angular ngrx
angular ngrx
asked Mar 28 at 21:58
ArashArash
2,6485 gold badges35 silver badges60 bronze badges
2,6485 gold badges35 silver badges60 bronze badges
basicallystore: Store<user: Object>
– Jota.Toledo
Mar 28 at 22:01
your class name which containsuser
&user.saveError
– Aravind
Mar 28 at 22:08
I would also add, spend some time looking using selectors: export const selectUserState = state => state.user as UserState; you can then used pipe(select(selectUserState))
– user9298624
Mar 28 at 23:32
add a comment
|
basicallystore: Store<user: Object>
– Jota.Toledo
Mar 28 at 22:01
your class name which containsuser
&user.saveError
– Aravind
Mar 28 at 22:08
I would also add, spend some time looking using selectors: export const selectUserState = state => state.user as UserState; you can then used pipe(select(selectUserState))
– user9298624
Mar 28 at 23:32
basically
store: Store<user: Object>
– Jota.Toledo
Mar 28 at 22:01
basically
store: Store<user: Object>
– Jota.Toledo
Mar 28 at 22:01
your class name which contains
user
& user.saveError
– Aravind
Mar 28 at 22:08
your class name which contains
user
& user.saveError
– Aravind
Mar 28 at 22:08
I would also add, spend some time looking using selectors: export const selectUserState = state => state.user as UserState; you can then used pipe(select(selectUserState))
– user9298624
Mar 28 at 23:32
I would also add, spend some time looking using selectors: export const selectUserState = state => state.user as UserState; you can then used pipe(select(selectUserState))
– user9298624
Mar 28 at 23:32
add a comment
|
1 Answer
1
active
oldest
votes
There is no specific type since the store is untyped but you can define interfaces to make it typed for development. What for StoreModule.forFeature('user', userReducer.reducer)
does is it adds a property user
in the root state that will hold the feature state. The Store you inject always contains all the state for the whole application that is why you have to use selectors. There are two possibilities how you could go about typing the store.
The first is to just focus on what you see inside the feature module and ignore the rest. Then it is similar to what is suggested in the comments.
For example if you defined a state for your feature that is created by the userReducer:
export interface UserState
saveError: string;
Then the because you named the feature user
the type for the store can be defined as:
export interface ApplicationState
user: UserState;
The second option if you know all the features in advance you can define an interface for all the structure of the store.
For example you have another feature with a different state:
export interface AnotherFeatureState
stateProperty: string;
Then the application state will be:
export interface ApplicationState
user?: UserState;
anotherFature?: AnotherFeatureState;
I made the state properties optional because the modules can be lazy loaded an in such a case the properties do not exists until the modules are loaded. If you don't do lazy loading you can assume they are always there.
In both cases how you type in the constructor is:
constructor(private store: Store<ApplicationState>)
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55407476%2fngrx-type-of-store-when-using-feature-module%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
There is no specific type since the store is untyped but you can define interfaces to make it typed for development. What for StoreModule.forFeature('user', userReducer.reducer)
does is it adds a property user
in the root state that will hold the feature state. The Store you inject always contains all the state for the whole application that is why you have to use selectors. There are two possibilities how you could go about typing the store.
The first is to just focus on what you see inside the feature module and ignore the rest. Then it is similar to what is suggested in the comments.
For example if you defined a state for your feature that is created by the userReducer:
export interface UserState
saveError: string;
Then the because you named the feature user
the type for the store can be defined as:
export interface ApplicationState
user: UserState;
The second option if you know all the features in advance you can define an interface for all the structure of the store.
For example you have another feature with a different state:
export interface AnotherFeatureState
stateProperty: string;
Then the application state will be:
export interface ApplicationState
user?: UserState;
anotherFature?: AnotherFeatureState;
I made the state properties optional because the modules can be lazy loaded an in such a case the properties do not exists until the modules are loaded. If you don't do lazy loading you can assume they are always there.
In both cases how you type in the constructor is:
constructor(private store: Store<ApplicationState>)
add a comment
|
There is no specific type since the store is untyped but you can define interfaces to make it typed for development. What for StoreModule.forFeature('user', userReducer.reducer)
does is it adds a property user
in the root state that will hold the feature state. The Store you inject always contains all the state for the whole application that is why you have to use selectors. There are two possibilities how you could go about typing the store.
The first is to just focus on what you see inside the feature module and ignore the rest. Then it is similar to what is suggested in the comments.
For example if you defined a state for your feature that is created by the userReducer:
export interface UserState
saveError: string;
Then the because you named the feature user
the type for the store can be defined as:
export interface ApplicationState
user: UserState;
The second option if you know all the features in advance you can define an interface for all the structure of the store.
For example you have another feature with a different state:
export interface AnotherFeatureState
stateProperty: string;
Then the application state will be:
export interface ApplicationState
user?: UserState;
anotherFature?: AnotherFeatureState;
I made the state properties optional because the modules can be lazy loaded an in such a case the properties do not exists until the modules are loaded. If you don't do lazy loading you can assume they are always there.
In both cases how you type in the constructor is:
constructor(private store: Store<ApplicationState>)
add a comment
|
There is no specific type since the store is untyped but you can define interfaces to make it typed for development. What for StoreModule.forFeature('user', userReducer.reducer)
does is it adds a property user
in the root state that will hold the feature state. The Store you inject always contains all the state for the whole application that is why you have to use selectors. There are two possibilities how you could go about typing the store.
The first is to just focus on what you see inside the feature module and ignore the rest. Then it is similar to what is suggested in the comments.
For example if you defined a state for your feature that is created by the userReducer:
export interface UserState
saveError: string;
Then the because you named the feature user
the type for the store can be defined as:
export interface ApplicationState
user: UserState;
The second option if you know all the features in advance you can define an interface for all the structure of the store.
For example you have another feature with a different state:
export interface AnotherFeatureState
stateProperty: string;
Then the application state will be:
export interface ApplicationState
user?: UserState;
anotherFature?: AnotherFeatureState;
I made the state properties optional because the modules can be lazy loaded an in such a case the properties do not exists until the modules are loaded. If you don't do lazy loading you can assume they are always there.
In both cases how you type in the constructor is:
constructor(private store: Store<ApplicationState>)
There is no specific type since the store is untyped but you can define interfaces to make it typed for development. What for StoreModule.forFeature('user', userReducer.reducer)
does is it adds a property user
in the root state that will hold the feature state. The Store you inject always contains all the state for the whole application that is why you have to use selectors. There are two possibilities how you could go about typing the store.
The first is to just focus on what you see inside the feature module and ignore the rest. Then it is similar to what is suggested in the comments.
For example if you defined a state for your feature that is created by the userReducer:
export interface UserState
saveError: string;
Then the because you named the feature user
the type for the store can be defined as:
export interface ApplicationState
user: UserState;
The second option if you know all the features in advance you can define an interface for all the structure of the store.
For example you have another feature with a different state:
export interface AnotherFeatureState
stateProperty: string;
Then the application state will be:
export interface ApplicationState
user?: UserState;
anotherFature?: AnotherFeatureState;
I made the state properties optional because the modules can be lazy loaded an in such a case the properties do not exists until the modules are loaded. If you don't do lazy loading you can assume they are always there.
In both cases how you type in the constructor is:
constructor(private store: Store<ApplicationState>)
edited Apr 20 at 11:10
marc_s
610k139 gold badges1169 silver badges1300 bronze badges
610k139 gold badges1169 silver badges1300 bronze badges
answered Mar 28 at 22:46
AlesDAlesD
4,4807 silver badges22 bronze badges
4,4807 silver badges22 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55407476%2fngrx-type-of-store-when-using-feature-module%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
basically
store: Store<user: Object>
– Jota.Toledo
Mar 28 at 22:01
your class name which contains
user
&user.saveError
– Aravind
Mar 28 at 22:08
I would also add, spend some time looking using selectors: export const selectUserState = state => state.user as UserState; you can then used pipe(select(selectUserState))
– user9298624
Mar 28 at 23:32