Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct equality check on oneOf decoders for virtual DOM diffing. #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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