Skip to content

Commit

Permalink
Merge pull request #1898 from ably/liveobjects/fixes
Browse files Browse the repository at this point in the history
Minor LiveObjects fixes/refactoring
  • Loading branch information
VeskeR authored Nov 8, 2024
2 parents 81237f3 + b73a15c commit e1e6cc7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 14 deletions.
9 changes: 0 additions & 9 deletions src/common/lib/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,6 @@ export function arrIntersectOb<K extends string>(arr: Array<K>, ob: Partial<Reco
return result;
}

export function arrSubtract<T>(arr1: Array<T>, arr2: Array<T>): Array<T> {
const result = [];
for (let i = 0; i < arr1.length; i++) {
const element = arr1[i];
if (arr2.indexOf(element) == -1) result.push(element);
}
return result;
}

export function arrDeleteValue<T>(arr: Array<T>, val: T): boolean {
const idx = arr.indexOf(val);
const res = idx != -1;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/liveobjects/liveobjectspool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class LiveObjectsPool {
*/
deleteExtraObjectIds(objectIds: string[]): void {
const poolObjectIds = [...this._pool.keys()];
const extraObjectIds = this._client.Utils.arrSubtract(poolObjectIds, objectIds);
const extraObjectIds = poolObjectIds.filter((x) => !objectIds.includes(x));

extraObjectIds.forEach((x) => this._pool.delete(x));
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/liveobjects/statemessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ export class StateMessage {

if (message.object?.map?.entries) {
for (const entry of Object.values(message.object.map.entries)) {
decodeMapEntry(entry, inputContext, decodeDataFn);
await decodeMapEntry(entry, inputContext, decodeDataFn);
}
}

if (message.operation?.map) {
for (const entry of Object.values(message.operation.map)) {
decodeMapEntry(entry, inputContext, decodeDataFn);
await decodeMapEntry(entry, inputContext, decodeDataFn);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/liveobjects/syncliveobjectsdatapool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ export class SyncLiveObjectsDataPool {
}

isEmpty(): boolean {
return this.size() === 0;
return this._pool.size === 0;
}

reset(): void {
this._pool = new Map<string, AnyDataEntry>();
this._pool.clear();
}

applyStateMessages(stateMessages: StateMessage[]): void {
Expand Down

0 comments on commit e1e6cc7

Please sign in to comment.