Reader small image

You're reading from  Vue.js 3 Design Patterns and Best Practices

Product typeBook
Published inMay 2023
Reading LevelIntermediate
PublisherPackt
ISBN-139781803238074
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Pablo David Garaguso
Pablo David Garaguso
author image
Pablo David Garaguso

Pablo David Garaguso was born in Argentina, and graduated from computer sciences in CAECE University Mar del Plata, and also an MBA in CEMA University in Buenos Aires. He worked as Computer Consultant and Manager in multiple positions in South America and Europe for almost 20 years. He currently works as a Solutions Architect and full-stack engineer for FamilySearch Int. in Finland. His systems and applications are used in Latin America, Europe, Africa, and other parts of the world.
Read more about Pablo David Garaguso

Right arrow

Experimenting with reactivity and Proxies patterns

It is time to put into practice what we have learned in this chapter under the light of patterns we saw in Chapter 2, Software Design Principles and Patterns, with a small experimental project. We want to create an option to make sessionStorage data behave like a reactive central state manager so that we can use it in our components. Possible uses for this approach could be to persist user-entered data during refreshes, alert components of data changes, and so on.

Since SessionStorage does not provide an API we can listen to, our approach will be to create a Proxy handler using the Decorator pattern, to match and keep synchronized the values in the store with an internal and private reactive property. We will wrap this in a singleton and use the Central State manager approach to share it in our application. Let’s start by creating our core service:

/services/sessionStorage.js

import { reactive } from 'vue&apos...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Vue.js 3 Design Patterns and Best Practices
Published in: May 2023Publisher: PacktISBN-13: 9781803238074

Author (1)

author image
Pablo David Garaguso

Pablo David Garaguso was born in Argentina, and graduated from computer sciences in CAECE University Mar del Plata, and also an MBA in CEMA University in Buenos Aires. He worked as Computer Consultant and Manager in multiple positions in South America and Europe for almost 20 years. He currently works as a Solutions Architect and full-stack engineer for FamilySearch Int. in Finland. His systems and applications are used in Latin America, Europe, Africa, and other parts of the world.
Read more about Pablo David Garaguso