Replies: 1 comment 3 replies
-
The warning informs you about technical limitation. Manipulating out-of-bound indices simply isn't supported and you could end up with broken code. Following won't work and you won't even get a warning: const arr = observable([], { proxy: false });
autorun(() => console.log(arr[1001]));
arr[1001] = 1;
console.log(arr.length); Generally out of bound indices are invisible to us. However, for performance reasons, we maintain a buffer of visible indicies, which is longer than the actual array length. So you only get the warning if the accessed index is still within the size of this buffer. However I think we can get rid of this limitation (and therefore the warning) for non-legacy proxied array, but I have to double check with @mweststrate |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there, in our production build we see developer warnings.
For example, if a developer tries to check in an array has an element in the index
i
, mobx throws an out of bounds warning.That's fine for development, but MobX should not pollute the console in production environments.
I looked for answers, on this, and so far, the only answers I've seen are "If you have a specific kind of warning, like out of bounds, then first check the array length before reading the Ith element". That's not a solution, that's a sardonic suggestion. For example, some arrays are sparse, so you must check the Ith element to see if it exists. Adding additional logic to read from an array is anti-pattern. Arrays are meant to be simple, and production code should not incur additional complexity to read from an array element i.
That was an example. I believe the simplest thing to do is to add a config param that allows developers to suppress warnings in production. Please add this and the world will be a little happier
Much love,
Nawar
Beta Was this translation helpful? Give feedback.
All reactions