Best Practice for Web Blocks Actions

Hello! 

I have a question and I would like you to clarify it, it's about Web Blocks. The logic must be on the side of the Blocks or his father? I'll give you an example so you can understand my idea. Imagine that you have a Block responsible for showing and changing the relative information of an Entity, the action responsible for changing the entity's information must be in the Block or in the Screen that uses the Block?

The big question is if blocks have logic/actions that directly affect the database or if they only show information (they are "dumb")?


Best Regards 

Hi,

I believe that the functionality present in the block must be all in the block. So, in the case of your example, I put everything inside the block. For me doesn't make sence have some part of the functionality in the block and other part outside. Who will consume that block want to consume all the concept abstracted by him.

But, you can have blocks just to show information and others to edit.

But every case must be analysed and we can have something that doesn't match this kind of approach.


Best regards,

Ricardo Pereira

mvp_badge
MVP

Hi Joao,

Blocks can have database related logic also there is no need to be just dumb UI (as you call it :) ), but it depends on need.

Usually if we want highly reusable block which can be used anywhere then you may need to keep logic in parent and use the block can have UI and non database logic. One example for this approach is when you want to implement some special widgets.

Where as there can be other scenarios where you need a block to function independently without much dependency on parent, in those cases you can keep all the database operation logic also in the block.

I don't know if this is best practice or not but this is how I decide my approach.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.