From 0c25989104bef9785bf112490c73541bd4bc1764 Mon Sep 17 00:00:00 2001 From: James Hu <51237606+jameshu111@users.noreply.github.com> Date: Thu, 4 May 2023 10:38:40 -0400 Subject: First attempt at remfromlsit --- src/fields/List.ts | 8 +++++++- src/fields/util.ts | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'src/fields') diff --git a/src/fields/List.ts b/src/fields/List.ts index 9c7794813..eb735dec2 100644 --- a/src/fields/List.ts +++ b/src/fields/List.ts @@ -77,10 +77,16 @@ const listHandlers: any = { item[OnUpdate] = updateFunction(list, i + start, item, this); } } + let hintArray: {val : any, index : number}[] = []; + for(let i = start; i < start + deleteCount; i++) { + hintArray.push({val : list.__fields[i], index : i}); + } const res = list.__fields.splice(start, deleteCount, ...items); + // console.log(hintArray); + // console.log(list.__fields); this[Update]( items.length === 0 && deleteCount - ? { op: '$remFromSet', items: removed, length: list.__fields.length } + ? { op: '$remFromSet', items: removed, hint : { start : start, deleteCount : deleteCount, hintArray : hintArray}, length: list.__fields.length } : items.length && !deleteCount && start === list.__fields.length ? { op: '$addToSet', items, length: list.__fields.length } : undefined diff --git a/src/fields/util.ts b/src/fields/util.ts index 92f3a69eb..254b70fa7 100644 --- a/src/fields/util.ts +++ b/src/fields/util.ts @@ -37,6 +37,7 @@ import { RichTextField } from './RichTextField'; import { SchemaHeaderField } from './SchemaHeaderField'; import { ComputedField } from './ScriptField'; import { ScriptCast, StrCast } from './Types'; +import { blue } from 'colors'; function _readOnlySetter(): never { throw new Error("Documents can't be modified in read-only mode"); @@ -377,7 +378,7 @@ export function updateFunction(target: any, prop: any, value: any, receiver: any diff?.op === '$addToSet' ? { $addToSet: { ['fields.' + prop]: SerializationHelper.Serialize(new List(diff.items)) } } : diff?.op === '$remFromSet' - ? { $remFromSet: { ['fields.' + prop]: SerializationHelper.Serialize(new List(diff.items)) } } + ? { $remFromSet: { ['fields.' + prop]: SerializationHelper.Serialize(new List(diff.items)), hint : diff.hint } } : { $set: { ['fields.' + prop]: SerializationHelper.Serialize(value) } }; !op.$set && ((op as any).length = diff.length); const prevValue = ObjectField.MakeCopy(lastValue as List); -- cgit v1.2.3-70-g09d2