lodash-es#differenceWith TypeScript Examples
The following examples show how to use
lodash-es#differenceWith.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: capacitor-filesystem-table.ts From capture-lite with GNU General Public License v3.0 | 6 votes |
async delete(tuples: T[], comparator = isEqual) {
return this.mutex.runExclusive(async () => {
this.assertTuplesExist(tuples, comparator);
await this.initialize();
const afterDeletion = differenceWith(
this.tuples$.value,
tuples,
comparator
);
this.tuples$.next(afterDeletion);
await this.dumpJson();
return tuples;
});
}
Example #2
Source File: capacitor-filesystem-table.ts From capture-lite with GNU General Public License v3.0 | 6 votes |
async update(tuples: T[], comparator: (x: T, y: T) => boolean) {
return this.mutex.runExclusive(async () => {
const afterDeletion = differenceWith(
this.tuples$.value,
tuples,
comparator
);
this.tuples$.next(afterDeletion.concat(tuples));
await this.dumpJson();
return tuples;
});
}
Example #3
Source File: capacitor-filesystem-table.ts From capture-lite with GNU General Public License v3.0 | 6 votes |
private assertTuplesExist(tuples: T[], comparator: (x: T, y: T) => boolean) {
const nonexistent = differenceWith(
tuples,
this.tuples$.value ?? [],
comparator
);
if (nonexistent.length !== 0) {
throw new Error(
`Cannot delete nonexistent tuples: ${JSON.stringify(nonexistent)}`
);
}
}
Example #4
Source File: capacitor-filesystem-table.ts From capture-lite with GNU General Public License v3.0 | 6 votes |
function assertNoDuplicatedTuples<T>(
tuples: T[],
comparator: (x: T, y: T) => boolean
) {
const unique = uniqWith(tuples, comparator);
if (tuples.length !== unique.length) {
const conflicted = differenceWith(tuples, unique, comparator);
throw new Error(`Tuples duplicated: ${JSON.stringify(conflicted)}`);
}
}