Skip to content

Commit

Permalink
fixes elm#32
Browse files Browse the repository at this point in the history
Correct equality check on oneOf decoders for virtual DOM diffing.
  • Loading branch information
rupertlssmith committed Mar 11, 2022
1 parent 063aaf0 commit 35e05a0
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/Elm/Kernel/Json.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ function _Json_equality(x, y)
return x.__index === y.__index && _Json_equality(x.__decoder, y.__decoder);

case __1_MAP:
return x.__func === y.__func && _Json_listEquality(x.__decoders, y.__decoders);
return x.__func === y.__func && _Json_arrayEquality(x.__decoders, y.__decoders);

case __1_AND_THEN:
return x.__callback === y.__callback && _Json_equality(x.__decoder, y.__decoder);
Expand All @@ -390,7 +390,7 @@ function _Json_equality(x, y)
}
}

function _Json_listEquality(aDecoders, bDecoders)
function _Json_arrayEquality(aDecoders, bDecoders)
{
var len = aDecoders.length;
if (len !== bDecoders.length)
Expand All @@ -407,6 +407,29 @@ function _Json_listEquality(aDecoders, bDecoders)
return true;
}

function _Json_listEquality(aDecoders, bDecoders)
{
var tempA = aDecoders;
var tempB = bDecoders;
while (tempA.b)
{
if (!tempB.b)
{
return false;
}
if (!_Json_equality(tempA.a, tempB.a))
{
return false;
}
tempA = tempA.b;
tempB = tempB.b;
}
if (tempB.b)
{
return false;
}
return true;
}

// ENCODE

Expand Down

0 comments on commit 35e05a0

Please sign in to comment.