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.

This talk has been presented at Vue.js Live 2024, check out the latest edition of this JavaScript Conference.

FAQ

Michael Thiessen is a full-time Vue educator who spends his time writing articles, sending out a weekly newsletter, creating courses, and giving talks.

The main focus of Michael Thiessen's talk is on reusable components, specifically how to write less code and make it more effective by making components reusable.

Inversion of control refers to giving up control of the application flow to other code. In reusable components, this is often achieved through scoped slots, allowing flexibility by letting components manage their own behavior.

Extension points allow specific parts of a component to be overridden as needed, making the component more flexible and reusable by selectively customizing its behavior.

The nesting level involves nesting scoped and regular slots throughout the component tree, allowing for the reuse of intermediate components and maximizing reusability across the application.

Reusable components are focused on efficiency and effectiveness, allowing developers to write less code and get more done. Clean components, on the other hand, are more about long-term maintainability.

The six levels of reusability mentioned in the talk are templating, configuration, adaptability, inversion, extension, and nesting.

Configuration props are used to create different variations of a single component's behavior. They often include boolean types and enum types, allowing toggling or selecting from a list of acceptable values.

The adaptability level uses slots to make components more flexible and adaptable to future use cases. This allows developers to expand what can be done in a component beyond what props allow.

The templating level involves reusing different parts of a template by encapsulating UI and logic inside components, making them reusable across different parts of an application.

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
State management is not limited to complex applications and transitioning to a store offers significant benefits. Pinia is a centralized state management solution compatible with Vue 2 and Vue 3, providing advanced devtools support and extensibility with plugins. The core API of Pinia is similar to Vuex, but with a less verbose version of stores and powerful plugins. Pinia allows for easy state inspection, error handling, and testing. It is recommended to create one file per store for better organization and Pinia offers a more efficient performance compared to V-rex.
Welcome to Nuxt 3
Vue.js London Live 2021Vue.js London Live 2021
29 min
Welcome to Nuxt 3
Top Content
Nux3 has made significant improvements in performance, output optimization, and serverless support. Nuxt Bridge brings the Nitro engine for enhanced performance and easier transition between Nuxt 2 and Nuxt Read. Nuxt 3 supports Webpack 5, Bytes, and Vue 3. NextLab has developed brand new websites using Docus technology. Nuxt.js is recommended for building apps faster and simpler, and Nuxt 2 should be used before migrating to Nuxt 3 for stability. DOCUS is a new project that combines Nuxt with additional features like content modules and an admin panel.
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 has seen significant adoption and improvements in performance, bundle size, architecture, and TypeScript integration. The ecosystem around Vue 3 is catching up, with new tools and frameworks being developed. The Vue.js.org documentation is undergoing a complete overhaul. PNIA is emerging as the go-to state management solution for Vue 3. The options API and composition API are both viable options in Vue 3, with the choice depending on factors such as complexity and familiarity with TypeScript. Vue 3 continues to support CDN installation and is recommended for new projects.
Design Systems: Walking the Line Between Flexibility and Consistency
React Advanced 2021React Advanced 2021
47 min
Design Systems: Walking the Line Between Flexibility and Consistency
Top Content
The Talk discusses the balance between flexibility and consistency in design systems. It explores the API design of the ActionList component and the customization options it offers. The use of component-based APIs and composability is emphasized for flexibility and customization. The Talk also touches on the ActionMenu component and the concept of building for people. The Q&A session covers topics such as component inclusion in design systems, API complexity, and the decision between creating a custom design system or using a component library.
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
In this Talk, the speaker demonstrates how to use Rust with WebAssembly in a Vue.js project. They explain that WebAssembly is a binary format that allows for high-performance code and less memory usage in the browser. The speaker shows how to build a Rust example using the WasmPack tool and integrate it into a Vue template. They also demonstrate how to call Rust code from a Vue component and deploy the resulting package to npm for easy sharing and consumption.
Vue: Feature Updates
Vue.js London 2023Vue.js London 2023
44 min
Vue: Feature Updates
Top Content
Watch video: Vue: Feature Updates
The Talk discusses the recent feature updates in Vue 3.3, focusing on script setup and TypeScript support. It covers improvements in defining props using imported types and complex types support. The introduction of generic components and reworked signatures for defined components provides more flexibility and better type support. Other features include automatic inference of runtime props, improved define emits and defined slots, and experimental features like reactive props destructure and define model. The Talk also mentions future plans for Vue, including stabilizing suspense and enhancing computer invalidations.

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 Kuznetsov
Mikhail Kuznetsov
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
Monitoring 101 for React Developers
React Summit US 2023React Summit US 2023
107 min
Monitoring 101 for React Developers
Top Content
WorkshopFree
Lazar Nikolov
Sarah Guthals
2 authors
If finding errors in your frontend project is like searching for a needle in a code haystack, then Sentry error monitoring can be your metal detector. Learn the basics of error monitoring with Sentry. Whether you are running a React, Angular, Vue, or just “vanilla” JavaScript, see how Sentry can help you find the who, what, when and where behind errors in your frontend project. 
Workshop level: Intermediate
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.