-
Notifications
You must be signed in to change notification settings - Fork 0
🐛 No-op left
transforms where the inserted objects are identical
#16
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
Conversation
@@ -669,7 +669,7 @@ json.transformComponent = function(dest, c, otherC, type) { | |||
} else if (otherC.oi !== void 0) { | |||
if (c.oi !== void 0 && c.p[common] === otherC.p[common]) { | |||
// left wins if we try to insert at the same place | |||
if (type === 'left') { | |||
if (type === 'left' && !deepEqual(otherC.oi, c.oi)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They can differ with od
though no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good prompt: I added a test case and realised that ops with no od
are handled by different code to ops with an od
💀
However, apart from the quirks of this codebase, I don't think it matters if they have different od
: they should still no-op. Ultimately, transform(a, b)
is saying: "make a
compatible with a document where b
has already been applied." So if we've already applied b
, its oi
is the current value. Applying a
— with the same oi
— would result in no change, regardless of what its od
is. Therefore, it should be a no-op.
5f3ca5b
to
d342559
Compare
test/json0.coffee
Outdated
it 'An attempt to re-add a key with an identical string becomes a no-op', -> | ||
assert.deepEqual [], type.transform [{p:['k'], oi:'x'}], [{p:['k'], oi:'x'}], 'left' | ||
assert.deepEqual [], type.transform [{p:['k'], oi:'x'}], [{p:['k'], oi:'x'}], 'right' | ||
|
||
it 'An attempt to re-replace a key with an identical string becomes a no-op', -> | ||
assert.deepEqual [], type.transform [{p:['k'], oi:'x', od: 'a'}], [{p:['k'], oi:'x', od: 'a'}], 'left' | ||
assert.deepEqual [], type.transform [{p:['k'], oi:'x', od: 'a'}], [{p:['k'], oi:'x', od: 'a'}], 'right' | ||
|
||
it 'An attempt to re-add a key with an identical object becomes a no-op', -> | ||
assert.deepEqual [], type.transform [{p:['k'], oi:{}}], [{p:['k'], oi:{}}], 'left' | ||
assert.deepEqual [], type.transform [{p:['k'], oi:{}}], [{p:['k'], oi:{}}], 'right' | ||
|
||
it 'An attempt to re-replace a key with an identical object becomes a no-op', -> | ||
assert.deepEqual [], type.transform [{p:['k'], oi:{}, od: 'a'}], [{p:['k'], oi:{}, od: 'a'}], 'left' | ||
assert.deepEqual [], type.transform [{p:['k'], oi:{}, od: 'a'}], [{p:['k'], oi:{}, od: 'a'}], 'right' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a test case for different od
At the moment if you transform two identical `oi` ops by one another, you get a no-op in the `right` case, but the `left` case results in a "silly" op whose `od` value is identical to its `oi` value. `left` vs `right` should simply determine which op wins in a tie. Since the two ops are identical, the `right` scenario and `left` scenario should also be identical. This change updates the transform behaviour to check this case, and results in a no-op regardless of `left` or `right` if the two ops are performing identical `oi`.
d342559
to
5ed2ca1
Compare
At the moment if you transform two identical
oi
ops by one another, you get a no-op in theright
case, but theleft
case results in a "silly" op whoseod
value is identical to itsoi
value.left
vsright
should simply determine which op wins in a tie. Since the two ops are identical, theright
scenario andleft
scenario should also be identical.This change updates the transform behaviour to check this case, and results in a no-op regardless of
left
orright
if the two ops are performing identicaloi
.