Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: add mapstub for overriding map implementation

thecodrrec5e5fca1bc3
diff --git a/packages/core/database/cached-collection.js b/packages/core/database/cached-collection.js
index 4559e2df5..4fbe64c98 100644
--- a/packages/core/database/cached-collection.js
+++ b/packages/core/database/cached-collection.js
@@ -1,16 +1,19 @@
import sort from "fast-sort";
import IndexedCollection from "./indexed-collection";
+import MapStub from "../utils/map";
export default class CachedCollection extends IndexedCollection {
constructor(context, type) {
super(context, type);
- this.map = new Map();
+ this.type = type;
+ this.map;
}
async init() {
await super.init();
const data = await this.indexer.readMulti(this.indexer.indices);
- this.map = new Map(data);
+ if (this.map && this.map.dispose) this.map.dispose();
+ this.map = new MapStub.Map(data, this.type);
}
async clear() {
@@ -41,6 +44,7 @@ export default class CachedCollection extends IndexedCollection {
}
getRaw() {
+ if (!this.map) return [];
return Array.from(this.map.values());
}
diff --git a/packages/core/utils/map.js b/packages/core/utils/map.js
new file mode 100644
index 000000000..f27cdcc03
--- /dev/null
+++ b/packages/core/utils/map.js
@@ -0,0 +1,13 @@
+var map = Map;
+class MapStub {
+ override(replacement) {
+ map = replacement;
+ }
+
+ get Map() {
+ return map;
+ }
+}
+
+const instance = new MapStub();
+module.exports = instance;