Skip to content

Commit

Permalink
Merge pull request #14 from serjek/data-change-immutable
Browse files Browse the repository at this point in the history
make DataChange type pure and immutable
  • Loading branch information
endel authored May 10, 2019
2 parents 45174a0 + 12d3a60 commit 7986393
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/io/colyseus/serializer/schema/Schema.hx
Original file line number Diff line number Diff line change
Expand Up @@ -316,16 +316,10 @@ 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
Expand Down Expand Up @@ -656,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 7986393

Please sign in to comment.