[Vuejs]-'Watching` localStorage for a change

0👍

This is exactly what the observer pattern is for.
You create an event "OnAppThemeChange". You can subscribe to that event with all your components.
Then whenever your App Theme changed you call your event, and all the components will refresh their App Theme.

This removes the need of Refreshing the theme every 2 seconds. It will only refresh when you actually change the theme.

Usefull links:

https://developer.mozilla.org/de/docs/Web/Guide/Events/Creating_and_triggering_events
https://refactoring.guru/design-patterns/observer

Leave a comment