vendredi 21 janvier 2022

Angular component Design pattern or principle

How should we get rid of if else/switch statement - business logic for specific components?

For example, I want to display data in my table and I have created 2 components. 1st is Smart component - table wrapper and 2nd is dumb component - table component.

<table-wrapper> smart component which is responsible to load the data and pass the data to my embedded component
   <table></table> dumb component which takes just input data and then output for emit the events
</table-wrapper>

As per Single responsibility principles, one component should do a single task, not multiple tasks. I have 100 tables and use this single component to render and display the data. In some tables, I have a couple of conditions for different scenarios which I don't want to write in my component which becomes very large files in the future and we end up writing an if-else/switch statement. How should we manage this type of additional separate logic for any component which is not responsible for a specific component. I am not quite sure if I need to follow any design pattern or principle.

Aucun commentaire:

Enregistrer un commentaire