From b87ba5098839bca2aeda92c3a8739366e4b16177 Mon Sep 17 00:00:00 2001 From: Endel Dreyer Date: Wed, 19 Aug 2020 09:34:17 -0300 Subject: [PATCH] trigger delete callbacks when collection is replaced --- .../Colyseus/Serializer/Schema/Schema.cs | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/Assets/Plugins/Colyseus/Serializer/Schema/Schema.cs b/Assets/Plugins/Colyseus/Serializer/Schema/Schema.cs index e7ab225f..da3a2cf8 100644 --- a/Assets/Plugins/Colyseus/Serializer/Schema/Schema.cs +++ b/Assets/Plugins/Colyseus/Serializer/Schema/Schema.cs @@ -402,25 +402,21 @@ public void Decode(byte[] bytes, Iterator it = null, ReferenceTracker refs = nul { refs.Remove(((IRef)previousValue).__refId); - //// - //// TODO: Trigger onRemove if structure has been replaced. - //// - //const deletes: DataChange[] = []; - //const entries: IterableIterator <[any, any] > = previousValue.entries(); - //let iter: IteratorResult <[any, any] >; - //while ((iter = entries.next()) && !iter.done) - //{ - // const [key, value] = iter.value; - // deletes.push({ - // op: OPERATION.DELETE, - // field: key, - // // dynamicIndex, - // value: undefined, - // previousValue: value, - // }); - //} - - //allChanges.set(previousValue['$changes'].refId, deletes); + var deletes = new List(); + var items = ((ISchemaCollection)previousValue).GetItems(); + + foreach (var key in items.Keys) + { + deletes.Add(new DataChange() + { + DynamicIndex = key, + Op = (byte)OPERATION.DELETE, + Value = null, + PreviousValue = items[key] + }); + } + + allChanges[(object)((IRef)previousValue).__refId] = deletes; } }