6 Levels of Reusability

Rate this content
Bookmark

Master the art of making your components highly reusable. The 6 Levels of Reusability show us how we can progressively make our components more and more reusable — as needed — and include powerful patterns and tools to help us reuse our code more easily.

Michael Thiessen
Michael Thiessen
23 min
25 Apr, 2024

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Today's Talk explores the concept of reusable components, focusing on levels of reusability such as inversion, extension, and nesting. Props are discussed as a means of achieving flexibility and configuration in components. Inversion of control and scoped slots are introduced to give components adaptability. Extension points provide the ability to override specific parts of an application within a single component. The Talk also covers the use of slots and nesting for component flexibility and reusability.

Available in Español: 6 Niveles de Reutilización

1. Introduction to Reusable Components

Short description:

Today we'll discuss reusable components and how they help us write less code while being more effective and efficient. The difference between reusable and clean components lies in maintainability versus reusability. I have developed a framework for determining the appropriate level of reusability for our components. We will focus on the last three levels of reusability: inversion, extension, and nesting. Level one is templating, where we reuse different parts of our template. The next level is configuration, where we create different variations of a single component.

Hey, my name is Michael Thiessen and today I'm going to be talking to you about reusable components. So if you don't know who I am, I'm going to give you just a little bit about myself before we get into this. I am a full time Vue educator, so that means that I spend all of my time writing articles, sending out my weekly newsletter, creating courses, and of course, giving talks just like this.

So today we're going to talk about reusable components. And the entire reason that we want to do this is so that we can write less code but get more done. We want to make our code more effective. We want to use our time more effectively. So we don't want to spend all of this time rewriting features and rewriting them over and over again. And so this talk is more focused on that aspect. The reusability of our code.

Some people often ask me about the difference between reusable components and clean components because I have another course called Clean Components Toolkit. And so they often ask what is the difference between these two things? And the difference is really about maintainability versus reusability. So clean components are more about long term maintainability, whereas reusable components are more about being more effective, being more efficient with our time, writing less code, and getting more done. Over the past few years, I have put together this framework for thinking about reusability so that we can better figure out exactly what amount of reusability we should add to our components. Because we don't want to add tons and tons of reusability to very simple one-off components. And we also want to make sure that we are adding the appropriate level of reusability to those components that we know we're going to use over and over and over again.

So the first level is templating. Then we have configuration, adaptability, inversion, which is perhaps my favorite one. We have extension. We also have nesting. So these first three levels are a little bit easier to understand and simpler. And they also don't give us as much power and flexibility as the later three. So we're going to focus our time on the last three, although we will go and cover these first three just so that we have the context because we need to build up into those last few levels of reusability.

So level one is templating. What we have here is that we want to reuse the different parts of our template. This is exactly what you're used to with building components and encapsulating different bits of UI and markup and logic inside of your components so that we can drop them in different places around our application and reuse them. This is pretty straightforward and not a lot to say about this one. Although of course there are a lot of nuances in how do we split these different components up? Where do we put the boundaries? Should we make a new component or not? And so we don't really have time to go into those nuances in depth in this talk, but those are there. The next level is configuration. And in this level we're going to create different variations of a single component, different variations in the behavior of that component.

2. Props: Configuration and Data

Short description:

We'll use props to achieve reusability and flexibility. Configuration props allow us to toggle behaviors and configure components. They can be boolean or enum types with multiple acceptable values. Data or state props involve passing application data, which can vary between users and runs of the application.

We're going to do this by using props. And with this there's a distinction between the three different kinds of props that we've got. So we have configuration props, we have data or state props, we also have template props. Configuration props, these are the star of the show here, as you can probably guess by the name. These configuration props are what drives this level of reusability. They are what allow us to toggle between different kinds of behavior and get a lot more reusability and flexibility out of each component.

So typically these are of a boolean type where we're either toggling something on or off. And good examples of this might be an is primary on a button. So you can have a primary button, you could have a secondary button. As well as things that are going to change like the UI of a component. So you might want to have a more compact view. Maybe you've got a video player and you want to show controls or hide the player controls. Different things like that. These are configuration props, because they allow us to configure and to change that behavior. The other kind of configuration prop are enum types or enumeration types. So these are where you have a list of acceptable values. It's not just a true or false toggle, but we instead have any number of values that we can pass into this. So one example is that the software I'm using to present this slideshow is Slidev. And it comes with a component built in to display a table of contents. And that has a prop called mode, which has three different values that you can pass to it. No other values are valid. So it can be all only current tree or only siblings. So that's a good example of a configuration prop.

Next up are data or state props. And this is probably exactly what you think it is. So we're taking our application data. Usually we're grabbing it from somewhere else, maybe an API, maybe your own API. Maybe it's entered in by the user. And we're passing that data around. This data is usually different when different users access this application or on different runs of the application.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Everything Beyond State Management in Stores with Pinia
Vue.js London Live 2021Vue.js London Live 2021
34 min
Everything Beyond State Management in Stores with Pinia
Top Content
When we think about Vuex, Pinia, or stores in general we often think about state management and the Flux patterns but not only do stores not always follow the Flux pattern, there is so much more about stores that make them worth using! Plugins, Devtools, server-side rendering, TypeScript integrations... Let's dive into everything beyond state management with Pinia with practical examples about plugins and Devtools to get the most out of your stores.
Welcome to Nuxt 3
Vue.js London Live 2021Vue.js London Live 2021
29 min
Welcome to Nuxt 3
Top Content
Explain about NuxtJS codebase refactor and challenges facing to implement Vue 3, Vite and other packages.
One Year Into Vue 3
Vue.js London Live 2021Vue.js London Live 2021
20 min
One Year Into Vue 3
Top Content
Vue 3 may still sound new to many users, but it's actually been released for over a year already. How did Vue 3 evolve during this period? Why did it take so long for the ecosystem to catch up? What did we learn from this process? What's coming next? We will discuss these questions in this talk!
Design Systems: Walking the Line Between Flexibility and Consistency
React Advanced Conference 2021React Advanced Conference 2021
47 min
Design Systems: Walking the Line Between Flexibility and Consistency
Top Content
Design systems aim to bring consistency to a brand's design and make the UI development productive. Component libraries with well-thought API can make this a breeze. But, sometimes an API choice can accidentally overstep and slow the team down! There's a balance there... somewhere. Let's explore some of the problems and possible creative solutions.
Utilising Rust from Vue with WebAssembly
Vue.js London Live 2021Vue.js London Live 2021
8 min
Utilising Rust from Vue with WebAssembly
Top Content
Rust is a new language for writing high-performance code, that can be compiled to WebAssembly, and run within the browser. In this talk you will be taken through how you can integrate Rust, within a Vue application, in a way that's painless and easy. With examples on how to interact with Rust from JavaScript, and some of the gotchas to be aware of.
Vue: Feature Updates
Vue.js London 2023Vue.js London 2023
44 min
Vue: Feature Updates
Top Content
The creator of Vue js gives an update on the new features of the technology.

Workshops on related topic

Vue3: Modern Frontend App Development
Vue.js London Live 2021Vue.js London Live 2021
169 min
Vue3: Modern Frontend App Development
Top Content
Featured WorkshopFree
Mikhail Kuznetcov
Mikhail Kuznetcov
The Vue3 has been released in mid-2020. Besides many improvements and optimizations, the main feature of Vue3 brings is the Composition API – a new way to write and reuse reactive code. Let's learn more about how to use Composition API efficiently.

Besides core Vue3 features we'll explain examples of how to use popular libraries with Vue3.

Table of contents:
- Introduction to Vue3
- Composition API
- Core libraries
- Vue3 ecosystem

Prerequisites:
IDE of choice (Inellij or VSC) installed
Nodejs + NPM
Build a Data-Rich Beautiful Dashboard With MUI X's Data Grid and Joy UI
React Summit 2023React Summit 2023
137 min
Build a Data-Rich Beautiful Dashboard With MUI X's Data Grid and Joy UI
Top Content
WorkshopFree
Sam Sycamore
Siriwat (Jun) Kunaporn
2 authors
Learn how to put MUI’s complete ecosystem to use to build a beautiful and sophisticated project management dashboard in a fraction of the time that it would take to construct it from scratch. In particular, we’ll see how to integrate the MUI X Data Grid with Joy UI, our newest component library and sibling to the industry-standard Material UI.
Table of contents:- Introducing our project and tools- App setup and package installation- Constructing the dashboard- Prototyping, styling, and themes - Joy UI features- Filtering, sorting, editing - Data Grid features- Conclusion, final thoughts, Q&A
Using Nitro – Building an App with the Latest Nuxt Rendering Engine
Vue.js London Live 2021Vue.js London Live 2021
117 min
Using Nitro – Building an App with the Latest Nuxt Rendering Engine
Top Content
Workshop
Daniel Roe
Daniel Roe
We'll build a Nuxt project together from scratch using Nitro, the new Nuxt rendering engine, and Nuxt Bridge. We'll explore some of the ways that you can use and deploy Nitro, whilst building a application together with some of the real-world constraints you'd face when deploying an app for your enterprise. Along the way, fire your questions at me and I'll do my best to answer them.
TresJS create 3D experiences declaratively with Vue Components
Vue.js London 2023Vue.js London 2023
137 min
TresJS create 3D experiences declaratively with Vue Components
Workshop
Alvaro Saburido
Alvaro Saburido
- Intro 3D - Intro WebGL- ThreeJS- Why TresJS- Installation or Stackblitz setup - Core Basics- Setting up the Canvas- Scene- Camera- Adding an object- Geometries- Arguments- Props- Slots- The Loop- UseRenderLoop composable- Before and After rendering callbacks- Basic Animations- Materials- Basic Material- Normal Material- Toon Material- Lambert Material- Standard and Physical Material- Metalness, roughness - Lights- AmbientLight- DirectionalLight- PointLights- Shadows- Textures- Loading textures with useTextures- Tips and tricks- Misc- Orbit Controls- Loading models with Cientos- Debugging your scene- Performance
Building Vue forms with VeeValidate
Vue.js London Live 2021Vue.js London Live 2021
176 min
Building Vue forms with VeeValidate
Workshop
Abdelrahman Awad
Abdelrahman Awad
In this workshop, you will learn how to use vee-validate to handle form validation, manage form values and handle submissions effectively. We will start from the basics with a simple login form all the way to using the composition API and building repeatable and multistep forms.

Table of contents:
- Introduction to vee-validate
- Building a basic form with vee-validate components
- Handling validation and form submissions
- Building validatable input components with the composition API
- Field Arrays and repeatable inputs
- Building a multistep form
Prerequisites:
VSCode setup and an empty Vite + Vue project.
Building full-stack GraphQL applications with Hasura and Vue 3
Vue.js London Live 2021Vue.js London Live 2021
115 min
Building full-stack GraphQL applications with Hasura and Vue 3
WorkshopFree
Gavin Ray
Gavin Ray
The frontend ecosystem moves at a breakneck pace. This workshop is intended to equip participants with an understanding of the state of the Vue 3 + GraphQL ecosystem, exploring that ecosystem – hands on, and through the lens of full-stack application development.

Table of contents
- Participants will use Hasura to build out a realtime GraphQL API backed Postgres. Together we'll walk through consuming it from a frontend and making the front-end reactive, subscribed to data changes.
- Additionally, we will look at commonly-used tools in the Vue GraphQL stack (such as Apollo Client and Urql), discuss some lesser-known alternatives, and touch on problems frequently encountered when starting out.
- Multiple patterns for managing stateful data and their tradeoffs will be outlined during the workshop, and a basic implementation for each pattern discussed will be shown.
Workshop level

NOTE: No prior experience with GraphQL is necessary, but may be helpful to aid understanding. The fundamentals will be covered.