grungnet/src/helpers/FakeStorage.js
2020-09-08 12:35:31 +10:00

24 lines
446 B
JavaScript

/**
* A faked local or session storage used when the user has disabled storage
*/
class FakeStorage {
data = {};
key(index) {
return Object.keys(this.data)[index] || null;
}
getItem(keyName) {
return this.data[keyName] || null;
}
setItem(keyName, keyValue) {
this.data[keyName] = keyValue;
}
removeItem(keyName) {
delete this.data[keyName];
}
clear() {
this.data = {};
}
}
export default FakeStorage;