Structuring A Massive Vuex Store

Rate this content
Bookmark

Dive deeply into the architecture of our massive Vuex store. This solution will always be easy to scale, read, and maintain no matter how huge your app is.

This talk has been presented at Vue.js London Live 2021, check out the latest edition of this Tech Conference.

FAQ

The speaker is Doma Gawidowic, also known as Dom.

Doma Gawidowic works at Orbital Witness, a London-based tech startup.

The main topic is structuring a massive UX store to create a scalable, flexible, and maintainable architecture.

A simple UX store includes state, actions, mutations, and getters.

Modules are a native UX feature that allow the separation of concerns by creating mini stores within a massive store.

The 'namespaced' attribute, when set to true, registers properties to a local namespace, preventing accidental access to local module properties.

You can avoid hard-coded strings by creating constants, exporting them, and using UX helpers like mapMutations, mapGetters, mapActions, and mapState.

For a massive app, it's recommended to have a root store folder with an index.js file, a modules folder containing separate folders for each module, and within each module folder, separate files for actions, getters, mutations, and types.

Developers can find the speaker's information on the conference's website under speakers, connect on Twitter, and check out the speaker's GitHub profile where the code is publicly available.

Domagoj Vidovic
Domagoj Vidovic
21 min
20 Oct, 2021

Comments

Sign in or register to post your comment.

Video Summary and Transcription

The Talk discusses the process of structuring a massive UX store using modules in Vue.js. It covers topics such as namespaces, triggering mutations, and improving store usage with map mutations. The importance of refactoring the folder structure and using separate files for actions, getters, and mutations is highlighted. The Talk concludes by mentioning the possibility of adding additional layers for splitting mutations and providing contact information for further inquiries.

1. Introduction to Structuring a Massive UX Store

Short description:

Hello, Vue.js London. Today, I will be talking about structuring a massive, massive UX store. Let's start with an example of a simple store and expand it step by step to solve the challenges of scalability and maintainability. We'll use modules to separate concerns and create mini stores within the main store.

Hello, Vue.js London. I'm so glad for speaking here today. My name is Doma Gawidowic. Feel free to call me Dom because it's just way easier to pronounce. I work at Orbital Witness, a cool London tech startup somewhere between prop tech and legal tech, and I also live in London.

Today, I will be talking about structuring a massive, massive UX store. How to create an architecture that is scalable, flexible, and maintainable. Currently, we're using this architecture at Orbital Witness. We have zero problems with it. Let's dive in.

I will start with an example of a simple store. I will be expanding that store in every step and presenting you the challenges we need to solve and, obviously, solve it. We're gonna start with the simplest store possible. We're using create store from UX, and we're creating an empty store with empty state actions, mutations, and getters. I won't be explaining those. I assume that you already know that. I will focus on how to create a store and make it scalable, make it appropriate for usage in huge apps.

Let's add some properties here now. Usually in your huge apps, you're going to have thousands of different properties. Right now, only two of them are enough, username and organization name, and obviously some mutations to set both. What would happen if this file had thousands of properties? You can imagine, just like adding, adding, adding things here, and file will just become bigger and bigger and bigger. We don't want to do that. If we're going to do that, why don't we just keep all of our code in app.vue and forget about components? Jokes aside.

Let's see how can we fix this problem. To do so, we're gonna use a native UX feature called modules. Modules allow us to separate the concerns, to isolate different parts of the store, and to make mini stores within our massive, massive store. Take a look at user module, for example, here, we took everything connected to the user, so name and it's mutation to set that name. We are also passing actions and getters as an empty object because we don't have any right now. And what is really important here is that namespaced attribute which is set to true. Namespaced attribute allows us to register those properties for that mini store to local namespace, to local namespace of that module.

2. Using Namespaces and Triggering Mutations

Short description:

In this part, we learn about accessing properties from any module, preventing accidental access, using namespaces, and exporting modules. We also discuss the importance of avoiding hard-coded strings and the two ways to trigger mutations.

In that way, we can access those properties from any other module, which is good because namespace set to true prevents us from accidentally accessing some of the local modules properties. You might think of that as a limitation, right? Because sometimes you actually need to trigger some methods from the different modules, but you can't right now. Well, you can, but you need to have an intent to do it. So it is possible, but you just need to have an intent. But this is definitely good because we're preventing those accidental triggering. You can have same state properties, with the same name or mutations, actions, gathers with the same name, namespace set to true allows us that. And its default value is false.

In that way, all properties will be registered at the global namespace. Maybe you want to do that, but just be careful about it. Organization module is literally the same. So we took everything connected to organization, set namespace to true, and we're exporting default that object. If we take a look at index.js file, the things have changed a bit. So now we have user module and organization module. We need to import them. And then we need to pass them to modules object. We're mapping those important modules to a certain name. Right now it's user and organization. This is cool. So we've already separated our store in different modules. They are isolated. We can't access them by an accident, but there's still something we need to solve.

Let's see, how can we use these mutations right now? We as developers hate hard-coded strings. They're not maintainable. They're not scalable. If you need to change something in your project, you literally have to search the whole code base and replace it. You can do search replace over the whole code base and then make crazy mess. It's a recipe for bugs. Don't use hard-coded strings. Right now, we don't have any other options because we can trigger mutations in two ways. First one, directly accessing the store object and triggering, for example, action send mutations.

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.
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
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.
Local State and Server Cache: Finding a Balance
Vue.js London Live 2021Vue.js London Live 2021
24 min
Local State and Server Cache: Finding a Balance
Top Content
This Talk discusses handling local state in software development, particularly when dealing with asynchronous behavior and API requests. It explores the challenges of managing global state and the need for actions when handling server data. The Talk also highlights the issue of fetching data not in Vuex and the challenges of keeping data up-to-date in Vuex. It mentions alternative tools like Apollo Client and React Query for handling local state. The Talk concludes with a discussion on GitLab going public and the celebration that followed.

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
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.
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
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 Pinia From Scratch
Vue.js Live 2024Vue.js Live 2024
70 min
Building Pinia From Scratch
Workshop
Eduardo San Martin Morote
Eduardo San Martin Morote
Let's dive into how Pinia works under the hood by building our own `defineStore()`. During this workshop we will cover some advanced Vue concepts like dependency Injection and effect scopes. It will give you a better understanding of Vue.js Composition API and Pinia. Requirements: experience building applications with Vue and its Composition API.