Schema Validation with Proxies possible error
alexamy opened this issue · 1 comments
alexamy commented
There is a code on p. 195 (6.1.3 Schema Validation with Proxies) that isnt working for me.
const validations = new Map()
const validator = {
set(target, key, value) {
if (validations.has(key)) {
return validations[key](value)
}
return Reflect.set(target, key, value)
}
}
I suggest to change return validations[key](value) to validations(key)(value), because of:
Mapobject dont support accessing through[], only throughgetmethod.- If we
returnresult of validation, we dont actually reach setting value attarget[key]. If we just validate value by direct method call ofvalidationsobject, as I suggesting, we throw error in that method if value isnt valid, or bypass this method in case of valid value and reach setting the value inReflect.set.
bevacqua commented
- You mean
validations.get(key)(value), right? Could you issue a PR?