简体   繁体   中英

Can lazy loaded features communicate state between features with ngrx in Angular 6?

If I have an app that uses lazy loading , and also using ngrx to manage state, I have a state instance for each feature with its own reducers, actions, etc. So for example:

product-feature
    product-edit
    product-add
    product-admin
    state
        product.reducer.ts
        product.actions.ts
        product.effects.ts
        product.index.ts
customer-feature
    customer-edit
    customer-add
    customer-admin
    state
        customer.reducer.ts
        customer.actions.ts
        customer.effects.ts
        customer.index.ts

With this structure, my main question is can the state between product-feature communicate and use the state between customer-feature ? If I, as a user, go to customer-feature , but the customer-feature needed some state information from the product-feature , would it still render and get the data even though the product-feature was never created because the user did not go to it (via lazy loading)?

Most examples I see online deal with ngrx as one AppState and don't do lazy loading, and the lazy loading examples I see that do communication between components are parent/child. Some articles I read say that you need to extend the app state to include the feature state, as the feature state cannot be referenced in the app state. The instance I am wondering is communicating state between sibling features. Is this possible with ngrx via lazy loading?

Thanks.

ngrx will merge the new state of the lazy loaded module with the current state, and that will happen only when you navigate to one of the routes of your lazy loaded module, so if your product-feature is not loaded, you will not have access to it's store.

i suggest to move the part you need in your customer-feature, or you can create a shared module for that

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM