github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/app/utils/properties/local-storage.js (about) 1 import { computed } from '@ember/object'; 2 3 // An Ember.Computed property that persists set values in localStorage 4 // and will attempt to get its initial value from localStorage before 5 // falling back to a default. 6 // 7 // ex. showTutorial: localStorageProperty('nomadTutorial', true), 8 export default function localStorageProperty(localStorageKey, defaultValue) { 9 return computed({ 10 get() { 11 const persistedValue = window.localStorage.getItem(localStorageKey); 12 return persistedValue ? JSON.parse(persistedValue) : defaultValue; 13 }, 14 set(key, value) { 15 window.localStorage.setItem(localStorageKey, JSON.stringify(value)); 16 return value; 17 }, 18 }); 19 }