Search code examples
angularwebpackreduxstorengrx

How to embed a ngrx store in a package based on angular while it can be mounted on the consumer?


As redux pattern has the single truth, if I pack my project using ngrx , how does the consumer mount this store node on his store (if has)? Or how can I expose my store for the consumer to mount?


Solution

  • In your package you should call StoreModule.forFeature and EffectsModule.forFeature to provide your reducers and effects.

    Then when a user installs your package and imports your module it will work out of the box. The user has to import StoreModule.forRoot and EffectsModule.forRoot in the same module or in any of its parents.