Skip to content

Commit

Permalink
make DataChange type pure and immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
serjek committed May 10, 2019
1 parent 2412d23 commit 12d3a60
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/io/colyseus/serializer/schema/Schema.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
public var items:Array<T> = [];
Expand Down Expand Up @@ -372,6 +367,7 @@ class ArraySchema<T> {

}

@:keep
@:generic
class MapSchema<T> {
public var items:Map<String, T> = new Map<String, T>();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 12d3a60

Please sign in to comment.