Item predicate matching
This commit is contained in:
@@ -125,32 +125,10 @@ class SingletonManager {
|
|||||||
|
|
||||||
filterItemsWithPredicate(items, predicate) {
|
filterItemsWithPredicate(items, predicate) {
|
||||||
return items.filter((candidate) => {
|
return items.filter((candidate) => {
|
||||||
return this.itemSatisfiesPredicate(candidate, predicate);
|
return candidate.satisfiesPredicate(predicate);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
itemSatisfiesPredicate(candidate, predicate) {
|
|
||||||
for(var key in predicate) {
|
|
||||||
var predicateValue = predicate[key];
|
|
||||||
var candidateValue = candidate[key];
|
|
||||||
if(typeof predicateValue == 'object') {
|
|
||||||
// Check nested properties
|
|
||||||
if(!candidateValue) {
|
|
||||||
// predicateValue is 'object' but candidateValue is null
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!this.itemSatisfiesPredicate(candidateValue, predicateValue)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(candidateValue != predicateValue) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
angular.module('app').service('singletonManager', SingletonManager);
|
angular.module('app').service('singletonManager', SingletonManager);
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ describe("notes and tags", () => {
|
|||||||
expect(tag.notes.length).to.equal(0);
|
expect(tag.notes.length).to.equal(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.only('resets cached note tags string when tag is renamed', () => {
|
it('resets cached note tags string when tag is renamed', () => {
|
||||||
let modelManager = Factory.createModelManager();
|
let modelManager = Factory.createModelManager();
|
||||||
|
|
||||||
let pair = createRelatedNoteTagPair();
|
let pair = createRelatedNoteTagPair();
|
||||||
@@ -384,7 +384,15 @@ describe("syncing", () => {
|
|||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
it('syncing a note many times does not cause duplication', async () => {
|
const wait = (secs) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
setTimeout(function () {
|
||||||
|
resolve();
|
||||||
|
}, secs * 1000);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
it.only('syncing a note many times does not cause duplication', async () => {
|
||||||
modelManager.resetLocalMemory();
|
modelManager.resetLocalMemory();
|
||||||
let pair = createRelatedNoteTagPair();
|
let pair = createRelatedNoteTagPair();
|
||||||
let noteParams = pair[0];
|
let noteParams = pair[0];
|
||||||
@@ -394,17 +402,20 @@ describe("syncing", () => {
|
|||||||
let note = modelManager.allItemsMatchingTypes(["Note"])[0];
|
let note = modelManager.allItemsMatchingTypes(["Note"])[0];
|
||||||
let tag = modelManager.allItemsMatchingTypes(["Tag"])[0];
|
let tag = modelManager.allItemsMatchingTypes(["Tag"])[0];
|
||||||
|
|
||||||
for(var i = 0; i < 25; i++) {
|
for(var i = 0; i < 9; i++) {
|
||||||
note.setDirty(true);
|
note.setDirty(true);
|
||||||
tag.setDirty(true);
|
tag.setDirty(true);
|
||||||
await syncManager.sync();
|
await syncManager.sync();
|
||||||
|
syncManager.clearSyncToken();
|
||||||
expect(tag.content.references.length).to.equal(1);
|
expect(tag.content.references.length).to.equal(1);
|
||||||
expect(note.tags.length).to.equal(1);
|
expect(note.tags.length).to.equal(1);
|
||||||
expect(tag.notes.length).to.equal(1);
|
expect(tag.notes.length).to.equal(1);
|
||||||
expect(modelManager.allItems.length).to.equal(2);
|
expect(modelManager.allItems.length).to.equal(2);
|
||||||
|
console.log("Waiting 1.1s...");
|
||||||
|
await wait(1.1);
|
||||||
|
|
||||||
}
|
}
|
||||||
}).timeout(10000);
|
}).timeout(20000);
|
||||||
|
|
||||||
it("handles signing in and merging data", async () => {
|
it("handles signing in and merging data", async () => {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user