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;









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?










share|improve this question


























  • 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


















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?










share|improve this question


























  • 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














0












0








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?










share|improve this question















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






share|improve this question














share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 21:58









ArashArash

2,6485 gold badges35 silver badges60 bronze badges




2,6485 gold badges35 silver badges60 bronze badges















  • 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


















  • 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

















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













1 Answer
1






active

oldest

votes


















0


















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>)





share|improve this answer





























    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
    );



    );














    draft saved

    draft discarded
















    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









    0


















    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>)





    share|improve this answer
































      0


















      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>)





      share|improve this answer






























        0














        0










        0









        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>)





        share|improve this answer
















        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>)






        share|improve this answer















        share|improve this answer




        share|improve this answer








        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

































            draft saved

            draft discarded















































            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.




            draft saved


            draft discarded














            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





















































            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









            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현