This repository has been archived on 2022-08-19. You can view files and clone it, but cannot push or open issues or pull requests.
hydrogen-web/src/matrix/storage/memory/stores/Store.js
Bruno Windels 001dbefbcf stop using default exports
because it becomes hard to remember where you used them and where not
2020-04-20 21:26:39 +02:00

28 lines
826 B
JavaScript

export class Store {
constructor(storeValue, writable) {
this._storeValue = storeValue;
this._writable = writable;
}
// makes a copy deep enough that any modifications in the store
// won't affect the original
// used for transactions
cloneStoreValue() {
// assumes 1 level deep is enough, and that values will be replaced
// rather than updated.
if (Array.isArray(this._storeValue)) {
return this._storeValue.slice();
} else if (typeof this._storeValue === "object") {
return Object.assign({}, this._storeValue);
} else {
return this._storeValue;
}
}
assertWritable() {
if (!this._writable) {
throw new Error("Tried to write in read-only transaction");
}
}
}