Do you avoid the DOM in your components?
23/04/2016 8:30 AM by
For this to work well, there has to be a clear separation between the component’s logic and the component’s view – which means avoiding using the DOM in your component’s code. This gives a few further advantages:
- Smaller component code making it easier to maintain
- Faster running and easier to write unit tests
- Easier for designers to get involved
This means that the component's state must expose things that are useful to the template as public properties or fields, and the template should read these fields to draw itself.
- This component manipulates the DOM directly to show and hide the menu
- This component sets component state, which the template can use. It is simpler, more descriptive and easier to test
Do you feel this rule needs an update?