Subscribe on changes!

readonly() breaks comparison between objects

avatar
Nov 23rd 2021

Version

3.2.21

Problem

I had an object A that used some data from a readonly object B, but after reassigning the props from object A and try to compare the prop to the equivalent data from object B, the result of the comparison was false when I expected to be true.

I managed to work around this by comparing the internal properties from both objects, but I'd like to know what it's expected to return in the case bellow

Steps to reproduce

class Type {
    constructor(code) {
        this.code = code;
    }
    
    getCode() {
        return this.code;
    }
}

simpler = readonly({ a: new Type(0), b: new Type(1) });
moreComplex = reactive({ a: simpler.a, b: simpler.b });
console.log(`Before: ${moreComplex.a === simpler.a}`);
moreComplex.a = simpler.b;
moreComplex.a = simpler.a;
console.log(`After: ${moreComplex.a === simpler.a}`);
avatar
Nov 23rd 2021

Hello, thank you for taking time filling this issue!

However, we kindly ask you to use our Issue Helper when creating new issues, in order to ensure every issue provides the necessary information for us to investigate. This explains why your issue has been automatically closed by me (your robot friend!).

I hope to see your helper-created issue very soon!

avatar
Nov 25th 2021

Looks like a legit bug, but a bit of an edge case.

avatar
Nov 25th 2021

Thank you