You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Welcome to MobX. Please provide as much relevant information as possible!
I have a:
Idea:
What problem would it solve for you? Sometimes I need to have reactions/computed values that change an array of immutable object references, so it would be nice to have a shallow array comparer
Do you think others will benefit from this change as well and it should in core package (see also mobx-utils)? It should be on the core package since that's where comparers are
Are you willing to (attempt) a PR yourself? Might
I have stumbled several times on a situation where I was generating a computed value that generated a new array of references to immutable objects. In this case the deep comparer had too much of a performance hit and was unecessary, so I had to use a function like this:
function shallowCompare(a: ReadonlyArray<any>, b: ReadonlyArray<any>) {
if (comparer.default(a, b)) {
return true;
}
if (!Array.isArray(a) || !Array.isArray(b)) {
return false;
}
const aLen = a.length, bLen = b.length;
if (aLen !== bLen) {
return false;
}
for (let i = 0; i <= aLen; i++) {
if (!comparer.default(a[i], b[i])) {
return false;
}
}
return true;
}
for this reason I think it could be a nice addition to the core comparers.
The text was updated successfully, but these errors were encountered:
Or maybe it should just be added as part of the default comparer itself? I don't see any situations where it could be harmful (except for performance perhaps, but then in those cases the identity comparer could be used anyway)
Welcome to MobX. Please provide as much relevant information as possible!
I have a:
I have stumbled several times on a situation where I was generating a computed value that generated a new array of references to immutable objects. In this case the deep comparer had too much of a performance hit and was unecessary, so I had to use a function like this:
for this reason I think it could be a nice addition to the core comparers.
The text was updated successfully, but these errors were encountered: