0

We're developing an Angular Living Styleguide at the moment. We plan to develop components in this styleguide and use them in our Apps.

For the apps, we would also like to use the redux pattern: https://github.com/angular-redux/store

Which I could not find is: How to chain components, that are imported via npm packages, to the redux store?

  • Should the store be injected as a Service in the component? This goes against decoupling. And what about double components, which would then have the same dispatch message?
  • Should the store be given to the compontent via @Input? Then other variables like dispatch-strings must also be passed to the Component. (e.g. a button - which action to dispatch when pressed)
  • Should I implement a service, which handles all the redux stuff, including the component giving the dispatch-message to the service? This seems like re-implementing redux to me.
skink
  • 5,133
  • 6
  • 37
  • 58
Florian Gössele
  • 4,376
  • 7
  • 25
  • 49
  • Could you please explain your edit, @Joulukuusi ? How to generally import components is clear to me, the thing (now missing in the title) is about importing components that use redux. Or am I missing some point? – Florian Gössele Oct 27 '17 at 07:41
  • 2
    Please see the relevant question on SE.Meta: https://meta.stackexchange.com/questions/19190/ where the general idea is that tags should not be specified in the question titles – skink Oct 27 '17 at 17:07

1 Answers1

1

you can use services to manage your store, inside your service you can get variable from the store and dispatch the new values after calling an http call for example. to get a store value in components you can call a property of a service example:

books= this.storeService.books;

in case you want to add books in your component:

this.storeService.create(books);

on the other side (storeService.ts)

this.books = store.get('Books');

to get Books from the store and you dispatch the new value of books when you subscribe to your http post call that create new ones

....subscribe(data = > { this.store.dispatch({type: 'Books', payload : data.books});})
Fateh Mohamed
  • 20,445
  • 5
  • 43
  • 52