Skip to content

Instantly share code, notes, and snippets.

@molcik
Last active July 13, 2018 13:17
Show Gist options
  • Save molcik/16a723734c3d61c7cc74d7baf2c1c8c2 to your computer and use it in GitHub Desktop.
Save molcik/16a723734c3d61c7cc74d7baf2c1c8c2 to your computer and use it in GitHub Desktop.
/**
* SessionStorage for storing string values
*/
export function SessionStorage(
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 sessionStorage.getItem(decoratedPropertyName) || '';
},
set: function (newValue) {
sessionStorage.setItem(decoratedPropertyName, newValue);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment