4 ms·
Why would an integrated component not include it's logic plus presentation? Putting logic here and presentation there immediately leads to the need for a mechan
by hoodoof 10y ago
Why would an integrated component not include it's logic plus presentation? Putting logic here and presentation there immediately leads to the need for a mechanism to ensure that this version of the presentation is matched with that version of the logic.
The real objection seems to be "I'm smart and I don't like it", not some considered explanation of what the inherent reason is to separate logic and presentation.
The wider context is that these components are typically built within an organised class structure enabled by ES2015, and operate within an organised component lifecycle as defined by react. Integration of logic with presentation and code into a single component makes a great deal of sense to me - all I hear are haters griping from the sidelines about how it looks like PHP.
- flukus 10y ago> Why would an integrated component not include it's logic plus presentation? Typically this makes it hard to test the logic. That's the big reason why logic and presentation were separated in the first place. > Putting logic here and presentation there immediately leads to the need for a mechanism to ensure that this version of the presentation is matched with that version of the logic. In the past this was handled by compilers and tests.
- Chris_Newton 10y agoTypically this makes it hard to test the logic. Why? You have your underlying data model, and any associated constraints and business logic built around that data. This can be tested using whatever tools you normally like to use. Independent of that, you have how you want to render some or all of that data in some particular way, which is the part React handles. There are tools for testing this as well, though in practice I rarely use them as I don’t like to have any complicated logic at this level in my design anyway. If you do need to do some non-trivial work to get from the underlying data to the processed data that is used for rendering — perhaps selecting the top five items from a set by some criteria, or combining some conditions to see whether a control should be enabled or disabled — you can build an intermediate layer that sits between the underlying raw data and the rendering logic. Again, this is a typical architecture for large-scale UIs that has nothing specifically to do with React, and again, the code can be tested with your preferred tools. In short, contrary to the tweet, we aren’t actually writing code like that in real projects built using React.