Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema Validation with Proxies possible error #49

Open
alexamy opened this issue Feb 13, 2018 · 1 comment
Open

Schema Validation with Proxies possible error #49

alexamy opened this issue Feb 13, 2018 · 1 comment

Comments

@alexamy
Copy link
Contributor

@alexamy alexamy commented Feb 13, 2018

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:

  1. Map object dont support accessing through [], only through get method.
  2. If we return result of validation, we dont actually reach setting value at target[key]. If we just validate value by direct method call of validations object, 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 in Reflect.set.
@bevacqua
Copy link
Member

@bevacqua bevacqua commented Jul 4, 2018

  1. You mean validations.get(key)(value), right? Could you issue a PR?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.