ceth
ceth

Reputation: 45325

How to divide application to components strategy

Is there any guide how do I need to divide my application to separate components? For example here is part of my application:

enter image description here

Now (1) and (2) are separate components (which are placed inside component (3)). But I found out that i need to write many code to transport messages from component 1 to component 2 and back.

When user select value in the Component 1 I need to say Component 2 to redraw. When user read all articles in the Component 2 I need to say Component 1 to remove item from list.

Now I think it will be better to have one component instead of two separate components.

May be there is a good strategy/advice/article - how to split the application to separate components ?

Upvotes: 2

Views: 3370

Answers (1)

Jesse Carter
Jesse Carter

Reputation: 21207

The whole strength of Angular2 is the ability to break things down into reusable components. If you're considering breaking things apart into multiple components, a good question to ask is whether there will ever be a situation in your app where those new components exist apart from eachother. If you see potential for reuse then you definitely want to split them. It sounds like another fundamental problem you're running into is component interaction. Angular 2 cookbook provides an awesome example for component interaction leveraging Services and Rxjs. You can read more about that here.

Personally, I've been using @ngrx/store for Redux style state management in my Angular 2 apps. It provides a centralized place to store all your application state and greatly simplifies component interaction by allowing components to subscribe to the store for only the data that they require and allows for OnPush semantics.

Upvotes: 4

Related Questions