Skip to content

Instantly share code, notes, and snippets.

@ndc
Created January 5, 2020 14:18
Show Gist options
  • Save ndc/e95c2ddf33bf21597fa16ac8158fac73 to your computer and use it in GitHub Desktop.
Save ndc/e95c2ddf33bf21597fa16ac8158fac73 to your computer and use it in GitHub Desktop.
double exclamation mark
<template>
<div id="app">
<router-view />
</div>
</template>
<style>
</style>
<script>
import SettingsHelper from "./store/settings.js";
export default {
mounted() {
window.addEventListener("storage", this.onSettingsUpdated);
let settings = SettingsHelper.readFromLocalStorage();
this.$store.commit("updateSettings", settings);
},
beforeDestroy() {
window.removeEventListener("storage", this.onSettingsUpdated);
},
methods: {
onSettingsUpdated(event) {
let settings = SettingsHelper.readFromEvent(event);
if (!!settings) {
this.$store.commit("updateSettings", settings);
}
}
}
};
</script>
const settingsHelper = {
// ...
readFromEvent(event) {
if (event.key != "settings") {
return null;
}
let settings = JSON.parse(event.newValue);
if (!this.isSettingsValid(settings)) {
settings = this.resetSettings();
}
return settings;
}
// ...
}
export default settingsHelper;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment