Skip to content

Commit 195bdac

Browse files
Merge pull request #221 from salmanhasni/salman-220-fixing-map-ds
fixes #220
2 parents 13bf992 + af20e07 commit 195bdac

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/client/ground.db.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ Ground.Collection = class GroundCollection {
154154
Kernel.defer(() => {
155155

156156
// Add the document to minimongo
157-
if (!this._collection._docs._map[id]) {
158-
this._collection._docs._map[id] = EJSON.fromJSONValue(doc);
157+
if (!this._collection._docs._map.has(id)) {
158+
this._collection._docs._map.set([id], EJSON.fromJSONValue(doc));
159159

160160
// Invalidate the observers pr. document
161161
// this call is throttled
@@ -221,9 +221,9 @@ Ground.Collection = class GroundCollection {
221221
setDocument(doc, remove) {
222222
doc._id = strId(doc._id);
223223
if (remove) {
224-
delete this._collection._docs._map[doc._id];
224+
this._collection._docs._map.remove(doc._id);
225225
} else {
226-
this._collection._docs._map[doc._id] = EJSON.clone(doc);
226+
this._collection._docs._map.set(doc._id, EJSON.clone(doc));
227227
}
228228
this.invalidate();
229229
}
@@ -328,7 +328,7 @@ Ground.Collection = class GroundCollection {
328328

329329
clear() {
330330
this.storage.clear();
331-
this._collection._docs._map = {};
331+
this._collection._docs._map.clear()
332332
this.invalidate();
333333
}
334334

@@ -339,14 +339,15 @@ Ground.Collection = class GroundCollection {
339339
keep(cursors) {
340340
const arrayOfCursors = (Array.isArray(cursors)) ? cursors : [cursors];
341341
// Map the ground db storage into an array of id's
342-
const currentIds = Object.keys(this._collection._docs._map);
342+
let currentIds = this._collection._docs._map.keys()
343+
currentIds = Array.from(currentIds);
343344
// Map each cursor id's into one flat array
344345
const keepIds = arrayOfCursors.map((cursor) => cursor.map((doc) => strId(doc._id))).flat();
345346
// Remove all other documents from the collection
346347
const arrays = [currentIds, keepIds];
347348
for (const id of arrays.reduce((a, b) => a.filter((c) => !b.includes(c)))) {
348349
// Remove it from in memory
349-
delete this._collection._docs._map[id];
350+
this._collection._docs._map.delete(id)
350351
// Remove it from storage
351352
this.saveDocument({ _id: id }, true);
352353
}
@@ -355,7 +356,7 @@ Ground.Collection = class GroundCollection {
355356
}
356357

357358
toJSON() {
358-
return JSON.stringify(this._collection._docs._map);
359+
return JSON.stringify(Object.fromEntries(this._collection._docs._map.entries()))
359360
}
360361

361362
// Simulate the Event Emitter Api "once"

0 commit comments

Comments
 (0)