Created
January 5, 2020 14:18
-
-
Save ndc/e95c2ddf33bf21597fa16ac8158fac73 to your computer and use it in GitHub Desktop.
double exclamation mark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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