Fix array serializeDiff and resetDiff for null or undefined values.

This commit is contained in:
Madeorsk 2022-10-16 01:31:17 +02:00
parent fb118bd584
commit dfecfd141c

View File

@ -38,12 +38,18 @@ export class ArrayType<SerializedValueType, SharkitekValueType> extends Type<Ser
serializeDiff(value: SharkitekValueType[]): any serializeDiff(value: SharkitekValueType[]): any
{ {
if (value === undefined) return undefined;
if (value === null) return null;
// Serializing diff of all elements. // Serializing diff of all elements.
return value.map((value) => this.valueType.serializeDiff(value)); return value.map((value) => this.valueType.serializeDiff(value));
} }
resetDiff(value: SharkitekValueType[]): void resetDiff(value: SharkitekValueType[]): void
{ {
// Do nothing if it is not an array.
if (!Array.isArray(value)) return;
// Reset diff of all elements. // Reset diff of all elements.
value.forEach((value) => this.valueType.resetDiff(value)); value.forEach((value) => this.valueType.resetDiff(value));
} }