Last active
July 13, 2018 13:16
-
-
Save molcik/8ef04f415ff9306ea847fd24fe4eff78 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* 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