fix: send raw collections

This commit is contained in:
thecodrr
2020-03-23 15:06:12 +05:00
parent 025a953cea
commit 9439ba7739
6 changed files with 33 additions and 13 deletions

View File

@@ -148,13 +148,13 @@ class Merger {
await this._mergeArray(
tags,
id => this._db.tags.raw(id),
id => this._db.tags.tag(id),
item => this._db.tags.merge(item)
);
await this._mergeArray(
colors,
id => this._db.colors.raw(id),
id => this._db.colors.tag(id),
item => this._db.colors.merge(item)
);
@@ -182,20 +182,20 @@ class Prepare {
async get(lastSyncedTimestamp) {
this._lastSyncedTimestamp = lastSyncedTimestamp;
return {
notes: this._prepareForServer(this._db.notes.all),
notebooks: this._prepareForServer(this._db.notebooks.all),
notes: this._prepareForServer(this._db.notes.raw),
notebooks: this._prepareForServer(this._db.notebooks.raw),
delta: this._prepareForServer(await this._db.delta.all()),
text: this._prepareForServer(await this._db.text.all()),
tags: this._prepareForServer(this._db.tags.all),
colors: this._prepareForServer(this._db.colors.all),
trash: this._prepareForServer(this._db.trash.all),
tags: this._prepareForServer(this._db.tags.raw),
colors: this._prepareForServer(this._db.colors.raw),
trash: this._prepareForServer(this._db.trash.raw),
lastSynced: Date.now()
};
}
_prepareForServer(array) {
return tfun
.filter(`.deleted || .dateEdited > ${this._lastSyncedTimestamp}`)
.filter(`.deleted === true || .dateEdited > ${this._lastSyncedTimestamp}`)
.map(item => ({
id: item.id,
dateEdited: item.dateEdited,

View File

@@ -63,6 +63,10 @@ export default class Notebooks {
return notebook;
}
get raw() {
return this._collection.getRaw();
}
get all() {
return sort(this._collection.getAllItems()).desc(t => t.pinned);
}

View File

@@ -134,6 +134,10 @@ export default class Notes {
return new Note(this, note);
}
get raw() {
return this._collection.getRaw();
}
get all() {
return this._collection.getAllItems();
}
@@ -148,13 +152,13 @@ export default class Notes {
tagged(tag) {
return this._tagsCollection
.get(tag)
.notes(tag)
.map(id => this._collection.getItem(id));
}
colored(color) {
return this._colorsCollection
.get(color)
.notes(color)
.map(id => this._collection.getItem(id));
}

View File

@@ -12,13 +12,13 @@ export default class Tags {
return this._collection.init();
}
get(tag) {
notes(tag) {
const tagItem = this.all.find(t => t.title === tag);
if (!tagItem) return [];
return tagItem.noteIds;
}
raw(id) {
tag(id) {
const tagItem = this.all.find(t => t.id === id);
if (!tagItem) return;
return tagItem;
@@ -55,6 +55,10 @@ export default class Tags {
await this._collection.addItem(tag);
}
get raw() {
return this._collection.getRaw();
}
get all() {
return this._collection.getAllItems();
}

View File

@@ -35,6 +35,10 @@ export default class Trash {
});
}
get raw() {
return this._collection.getRaw();
}
get all() {
return this._collection.getAllItems(u => u.dateDeleted);
}

View File

@@ -62,10 +62,14 @@ export default class CachedCollection {
return this.map.get(id);
}
getRaw() {
return Array.from(this.map.values());
}
getAllItems(sortFn = u => u.dateCreated) {
let items = [];
this.map.forEach(value => {
if (value.deleted) return; // if item is deleted we skip it.
if (value.deleted) return;
items[items.length] = value;
});
return sort(items).desc(sortFn);