From the course: Web Components and Modularization: Practical Approaches
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
One-task principle
From the course: Web Components and Modularization: Practical Approaches
One-task principle
- [Narrator] The one task principle says a component should ideally only do one thing, one task. I say, ideally, because it's not always practical and not always feasible. To see the one task principle and practice consider our book card component. In the design this component can do two things. If you click on it, you're taken to the single view for the current book. If you click the add to cart button, the book is added to the cart, but you stay on the same current view. And once a book has been added to the cart, the state of the add to cart button changes to display the text in cart and a check mark icon instead. In other words, if we follow the one task principle this book card component needs to be broken down into several separate components, one for each task. But how do we do that? The key is to remember components can use other components. Let's simplify the book card component down to just two things. The…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.