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
With regular Proxy objects you can trigger an infinite loop by modifying an object that was just modified within the set handler:
let validator = {
set: function(obj, prop, value) {
if (prop === 'age') {
if (!Number.isInteger(value)) {
throw new TypeError('The age is not an integer');
}
if (value > 200) {
throw new RangeError('The age seems invalid');
}
}
console.log('new set');
person.age = 10;
// The default behavior to store the value
obj[prop] = value;
// Indicate success
return true;
}
};
let person = new Proxy({}, validator);
person.age = 15;
A developer is unlikely to make this kind of with a regular Proxy because they are small in scope and easy to understand. However, because Observable-Slim handles this for the user, it can become less clear what's going on if they set a proxy value for the same property within a handler function. If it's not possible to add a more helpful JS error without sacrificing performance, then we should at least include a helpful hint in the README.
The text was updated successfully, but these errors were encountered:
ElliotNB
changed the title
Add helpful hint in the README about avoiding infinite loops
Add helpful hint in the README about avoiding infinite recursion
Aug 21, 2018
With regular
Proxy
objects you can trigger an infinite loop by modifying an object that was just modified within theset
handler:A developer is unlikely to make this kind of with a regular
Proxy
because they are small in scope and easy to understand. However, because Observable-Slim handles this for the user, it can become less clear what's going on if they set a proxy value for the same property within a handler function. If it's not possible to add a more helpful JS error without sacrificing performance, then we should at least include a helpful hint in the README.The text was updated successfully, but these errors were encountered: