aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/server/websocket.ts36
1 files changed, 16 insertions, 20 deletions
diff --git a/src/server/websocket.ts b/src/server/websocket.ts
index e94b48f4f..42c84322b 100644
--- a/src/server/websocket.ts
+++ b/src/server/websocket.ts
@@ -320,7 +320,7 @@ export namespace WebSocket {
/**
* findClosestIndex() is a helper function that will try to find
* the closest index of a list that has the same value as
- * a specified argument/index pair.
+ * a specified argument/index pair.
* @param list the list to search through
* @param indexesToDelete a list of indexes that are already marked for deletion
* so they will be ignored
@@ -329,11 +329,11 @@ export namespace WebSocket {
* the data
* @returns the closest index with the same value or -1 if the element was not found.
*/
- function findClosestIndex(list: any, indexesToDelete: number[], value: any, hintIndex : number) {
+ function findClosestIndex(list: any, indexesToDelete: number[], value: any, hintIndex: number) {
let closestIndex = -1;
- for(let i = 0; i < list.length; i++) {
- if(list[i] == value && !indexesToDelete.includes(i)) {
- if(Math.abs(i - hintIndex) < Math.abs(closestIndex - hintIndex)) {
+ for (let i = 0; i < list.length; i++) {
+ if (list[i] === value && !indexesToDelete.includes(i)) {
+ if (Math.abs(i - hintIndex) < Math.abs(closestIndex - hintIndex)) {
closestIndex = i;
}
}
@@ -343,13 +343,13 @@ export namespace WebSocket {
/**
* remFromListField() receives the items to remove and a hint
- * from the client, and attempts to make the modification to the
- * server's copy of the data. If server's copy does not match
+ * from the client, and attempts to make the modification to the
+ * server's copy of the data. If server's copy does not match
* the client's after removal, the server will SEND BACk
* its version to the client.
* @param socket the socket that the client is connected on
* @param diff an object containing the items to remove and a hint
- * (the hint contains start index and deleteCount, the number of
+ * (the hint contains start index and deleteCount, the number of
* items to delete)
* @param curListItems the server's current copy of the data
*/
@@ -360,34 +360,30 @@ export namespace WebSocket {
const remListItems = diff.diff.$set[updatefield].fields;
const curList = (curListItems as any)?.fields?.[updatefield.replace('fields.', '')]?.fields.filter((f: any) => f !== null) || [];
const hint = diff.diff.$set.hint;
-
-
- if(hint) {
+
+ if (hint) {
// indexesToRemove stores the indexes that we mark for deletion, which is later used to filter the list (delete the elements)
let indexesToRemove: number[] = [];
- for(let i = 0; i < hint.deleteCount; i++) {
- if(curList[i + hint.start] == remListItems[i]) {
+ for (let i = 0; i < hint.deleteCount; i++) {
+ if (curList[i + hint.start] === remListItems[i]) {
indexesToRemove.push(i + hint.start);
continue;
}
let closestIndex = findClosestIndex(curList, indexesToRemove, remListItems[i], i + hint.start);
- if(closestIndex != -1) {
+ if (closestIndex !== -1) {
indexesToRemove.push(closestIndex);
} else {
- console.log("Item to delete was not found - index = -1");
+ console.log('Item to delete was not found - index = -1');
}
}
- diff.diff.$set[updatefield].fields = curList?.filter(
- (curItem: any, index : number) => !(indexesToRemove.includes(index))
- );
+ diff.diff.$set[updatefield].fields = curList?.filter((curItem: any, index: number) => !indexesToRemove.includes(index));
} else {
// go back to the original way to delete if we didn't receive
// a hint from the client
diff.diff.$set[updatefield].fields = curList?.filter(
- (curItem: any) => !remListItems.some((remItem: any) => (remItem.fieldId ? remItem.fieldId === curItem.fieldId :
- remItem.heading ? remItem.heading === curItem.heading : remItem === curItem))
+ (curItem: any) => !remListItems.some((remItem: any) => (remItem.fieldId ? remItem.fieldId === curItem.fieldId : remItem.heading ? remItem.heading === curItem.heading : remItem === curItem))
);
}