I was looking for logic when someone creates a new component in a web application on angularjs / angular , but I assume this is more general and can be applied to all interface based components.
I know that there are some principles like the one that should be abstract and reusable , but, for example, I saw in the angular docs that each individual route looks at a specific component (how it can be reused). Is there any solid question I could ask before creating a new component ?
To decide whether to create a component or not, I think you should answer the following questions:
This tip applies regardless of structure. A new component is usually created for one of two reasons:
(1) Resuability
. . , , . .
, , , , !
(2)
. , . . .
:
, . , / .
apponents.
, .
Angular, , , . , , , .
Ionic ,
<ion-header> <ion-navbar> <ion-title>Home</ion-title> </ion-navbar> </ion-header> <ion-content padding> <ion-list> <ion-item *ngFor="let u of users"> <ion-avatar item-left> <img src="{{u.ImgUrl}}"> </ion-avatar> <h2>{{u.Name}}</h2> <p>{{u.Status}}</p> </ion-item> </ion-list> </ion-content>
, ! , . , . , -, . . , . .
html, , , , angular, .
, ,
(i) Identify the responsibility. , components responsibility, , .
Identify the responsibility
components responsibility
(ii) When it is large. , 600 , , .
When it is large
(iii) When you want to reuse. , , .
When you want to reuse
3 , . , .
, , view/container, Angular, .
, , . ( ). . , .
, . , , .
AngularJS , React / ( ). , views components.
views
components
, , . , , - . , Angular. , , .
React docs:
, ? . , . , .JSON, , , (, , ) . , , , . , . https://facebook.imtqy.com/react/docs/thinking-in-react.html
, ? . , . , .
JSON, , , (, , ) . , , , . , . https://facebook.imtqy.com/react/docs/thinking-in-react.html
PS. Also think about performance. By separating components, you can control the life cycle of a small point of view, so basically, if your component shows one (atomic) part of the data, you can easily determine when the component should be updated. see shouldComponentUpdate().
shouldComponentUpdate()