From 12d3a609bdec7b0af0a2c0aa1781305ea649b506 Mon Sep 17 00:00:00 2001 From: Sergey Balitskiy Date: Fri, 10 May 2019 10:03:47 +0200 Subject: [PATCH] make DataChange type pure and immutable --- src/io/colyseus/serializer/schema/Schema.hx | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/io/colyseus/serializer/schema/Schema.hx b/src/io/colyseus/serializer/schema/Schema.hx index 9588f34..919c4ad 100644 --- a/src/io/colyseus/serializer/schema/Schema.hx +++ b/src/io/colyseus/serializer/schema/Schema.hx @@ -316,18 +316,13 @@ class Decoder { } } -class DataChange { - public var field:String; - public var value:Dynamic; - public var previousValue:Dynamic; - - public function new(field:String, value:Dynamic, previousValue:Dynamic) { - this.field = field; - this.value = value; - this.previousValue = previousValue; - } +typedef DataChange = { + var field(default,never):String; + var value(default,never):Any; + var previousValue(default,never):Any; } +@:keep @:generic class ArraySchema { public var items:Array = []; @@ -372,6 +367,7 @@ class ArraySchema { } +@:keep @:generic class MapSchema { public var items:Map = new Map(); @@ -654,7 +650,11 @@ class Schema { } if (hasChange) { - changes.push(new DataChange(field, (change == null) ? value : change, Reflect.getProperty(this, field))); + changes.push({ + field: field, + value: (change == null) ? value : change, + previousValue: Reflect.getProperty(this, field) + }); } Reflect.setField(this, field, cast value);