Skip to content

Commit 52afd2b

Browse files
committed
Remove more usages of lodash.
1 parent c00b9e2 commit 52afd2b

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

packages/powersync-sdk-common/src/client/AbstractPowerSyncDatabase.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Mutex } from 'async-mutex';
22
import { EventIterator } from 'event-iterator';
33
import Logger, { ILogger } from 'js-logger';
4-
import intersection from 'lodash/intersection';
54
import throttle from 'lodash/throttle';
65
import { DBAdapter, QueryResult, Transaction, isBatchedUpdateNotification } from '../db/DBAdapter';
76
import { SyncStatus } from '../db/crud/SyncStatus';
@@ -574,21 +573,20 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
574573
*/
575574
onChange(options?: SQLWatchOptions): AsyncIterable<WatchOnChangeEvent> {
576575
const resolvedOptions = options ?? {};
577-
const watchedTables = resolvedOptions.tables ?? [];
576+
const watchedTables = new Set(resolvedOptions.tables ?? []);
578577

579-
let throttledTableUpdates: string[] = [];
578+
let changedTables = new Set<string>();
580579
const throttleMs = resolvedOptions.throttleMs ?? DEFAULT_WATCH_THROTTLE_MS;
581580

582581
return new EventIterator<WatchOnChangeEvent>((eventOptions) => {
583582
const flushTableUpdates = throttle(
584583
() => {
585-
const changedTables = intersection(watchedTables, throttledTableUpdates);
586-
if (changedTables.length > 0) {
584+
if (changedTables.size > 0) {
587585
eventOptions.push({
588-
changedTables
586+
changedTables: [...changedTables]
589587
});
590588
}
591-
throttledTableUpdates = [];
589+
changedTables.clear();
592590
},
593591
throttleMs,
594592
{ leading: false, trailing: true }
@@ -610,7 +608,9 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
610608
? filteredTables
611609
: filteredTables.map((t) => t.replace(POWERSYNC_TABLE_MATCH, ''));
612610

613-
throttledTableUpdates.push(...mappedTableNames);
611+
for (let table of mappedTableNames) {
612+
changedTables.add(table);
613+
}
614614

615615
flushTableUpdates();
616616
}

packages/powersync-sdk-common/src/client/sync/bucket/CrudEntry.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import isEqual from 'lodash/isEqual';
2-
31
/**
42
* 64-bit unsigned integer stored as a string in base-10.
53
*
@@ -109,7 +107,7 @@ export class CrudEntry {
109107
}
110108

111109
equals(entry: CrudEntry) {
112-
return isEqual(this.toComparisonArray(), entry.toComparisonArray());
110+
return JSON.stringify(this.toComparisonArray()) == JSON.stringify(entry.toComparisonArray());
113111
}
114112

115113
/**

packages/powersync-sdk-common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import throttle from 'lodash/throttle';
2-
import defer from 'lodash/defer';
32

43
import Logger, { ILogger } from 'js-logger';
54

@@ -226,7 +225,7 @@ export abstract class AbstractStreamingSyncImplementation extends BaseObserver<S
226225
// A connection is active and messages are being received
227226
if (!this.syncStatus.connected) {
228227
// There is a connection now
229-
defer(() => this.triggerCrudUpload());
228+
Promise.resolve().then(() => this.triggerCrudUpload());
230229
this.updateSyncStatus({
231230
connected: true
232231
});

packages/powersync-sdk-common/src/db/crud/SyncStatus.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import isEqual from 'lodash/isEqual';
2-
31
export type SyncDataFlowStatus = Partial<{
42
downloading: boolean;
53
uploading: boolean;
@@ -49,7 +47,7 @@ export class SyncStatus {
4947
}
5048

5149
isEqual(status: SyncStatus) {
52-
return isEqual(this.options, status.options);
50+
return JSON.stringify(this.options) == JSON.stringify(status.options);
5351
}
5452

5553
getMessage() {

0 commit comments

Comments
 (0)