Skip to content

Instantly share code, notes, and snippets.

@molcik
Last active July 13, 2018 13:16
Show Gist options
  • Save molcik/8ef04f415ff9306ea847fd24fe4eff78 to your computer and use it in GitHub Desktop.
Save molcik/8ef04f415ff9306ea847fd24fe4eff78 to your computer and use it in GitHub Desktop.
/**
* LocalStorage for storing string values
*/
export function LocalStorage(
target: Object, // The prototype of the class
decoratedPropertyName: string // The name of the property
) {
// get and set methods
Object.defineProperty(target, decoratedPropertyName, {
get: function () {
return localStorage.getItem(decoratedPropertyName) || '';
},
set: function (newValue) {
localStorage.setItem(decoratedPropertyName, newValue);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment