btroncone / ngrx-examples

@ngrx examples and resources
371 stars 68 forks source link

Technical Review? #1

Closed NathanWalker closed 8 years ago

NathanWalker commented 8 years ago

Hi guys,

Your examples here have been extremely helpful in understanding how to setup ngrx/store in an application. I'm still learning but I have just pushed an integration here:

The relevant pieces are here: https://github.com/NathanWalker/angular2-seed-advanced/blob/master/src/frameworks/i18n.framework/state/multilingual.reducer.ts https://github.com/NathanWalker/angular2-seed-advanced/blob/master/src/frameworks/i18n.framework/state/multilingual.actions.ts Usage here: https://github.com/NathanWalker/angular2-seed-advanced/blob/master/src/frameworks/i18n.framework/components/lang-switcher.component.ts

Another reducer here: https://github.com/NathanWalker/angular2-seed-advanced/blob/master/src/frameworks/core.framework/state/route.reducer.ts Usage here: https://github.com/NathanWalker/angular2-seed-advanced/blob/master/src/frameworks/core.framework/common/route-common.component.ts

Combining others with those here: https://github.com/NathanWalker/angular2-seed-advanced/blob/master/src/main.web.ts#L26-L30

Curious if maybe I should follow the examples here: https://github.com/ngrx/angular2-store-example

Whenever you get a chance, I would greatly appreciate your feedback. Does this look like a good integration based on your understandings? Thank you so much.

btroncone commented 8 years ago

No problem, I'll take a look and let you know a bit later today. Thanks for your interest!

btroncone commented 8 years ago

A couple things I noticed:

1.) You generally will not need to call combine reducers, provideStore will combine reducers behind the scenes when you pass an object map of reducers. 2.) For storing route state, you can check out this middleware. 3.) It looks like you may be maintaining seperate state in one of your services (based on this call this.multilang.changeLang(action.payload.lang)). It would be better to move all state up to store and dispatch an action to update language state. 4.) Since your action service is really dispatching one action, you could dispatch the action from your service method rather then wrapping in a Subject. You could even remove the service and inject dispatcher into component for this use-case. 5.) Since 1.3 there is no need to dispatch from subscribe like this: .subscribe((action: Action) => store.dispatch(action));. Instead, since store is a BehaviorSubject, you can simply subscribe store to your actions$ stream: .subscribe(store);

Just a few thoughts after a cursory glance, I think it looks great! Good luck with your project!

NathanWalker commented 8 years ago

Excellent feedback @btroncone Thank you so much for your time looking at it! This really helps my understanding, I'll make adjustments based on this soon, you're the best!

btroncone commented 8 years ago

I thought you responded with another question but I do not see it here now. Feel free to message me on gitter at any time if you have additional questions, I don't mind at all!