Skip to content

Commit

Permalink
fix parsing 'null' in the state.
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed Nov 12, 2017
1 parent 15db901 commit aeded62
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Assets/Plugins/Colyseus/DeltaListener/Compare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ protected static void Generate(IndexedDictionary<string, object> mirror, Indexed
for (int i = 0; i < oldKeys.Count; i++)
{
var key = oldKeys [i];
if (obj.ContainsKey(key) && !(!obj.ContainsKey(key) && mirror.ContainsKey(key) && !(obj is List<object>)))
if (
obj.ContainsKey(key) &&
obj[key] != null &&
!(!obj.ContainsKey(key) && mirror.ContainsKey(key) &&
!(obj is List<object>))
)
{
var oldVal = mirror[key];
var newVal = obj[key];
Expand Down
17 changes: 17 additions & 0 deletions Assets/Tests/DeltaContainerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ public void ListenAddString() {
Assert.AreEqual (1, listenCalls);
}

[Test]
public void ListenAddNull() {
var newData = GetRawData ();
newData ["null_new"] = null;

var listenCalls = 0;
container.Listen ("null_new", (DataChange change) => {
listenCalls++;
Assert.AreEqual("add", change.operation);
Assert.AreEqual(null, change.value);
});

container.Set (newData);
Assert.AreEqual (1, listenCalls);
}

[Test]
public void ListenAddRemove() {
var newData = GetRawData ();
Expand Down Expand Up @@ -198,6 +214,7 @@ protected IndexedDictionary<string, object> GetRawData () {
}));
data.Add ("players", players);
data.Add ("turn", "none");
data.Add ("null", null);
data.Add ("messages", new List<object> { "one", "two", "three" });
return data;
}
Expand Down

0 comments on commit aeded62

Please sign in to comment.