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

Attach moment to ajv instance? #1

Closed
epoberezkin opened this issue Sep 5, 2016 · 4 comments
Closed

Attach moment to ajv instance? #1

epoberezkin opened this issue Sep 5, 2016 · 4 comments

Comments

@epoberezkin
Copy link

It may be a nicer solution than passing via context - from version 4.6.0 all custom keywords (but "validate") receive the third parameter - schema compilation context that has reference to ajv instance it.self. In this way if the moment is attached to the instance, you can access it from custom keywords.

Or you could make moment a dependency of this package (there are pros and cons of course...)

@cludden
Copy link
Owner

cludden commented Sep 5, 2016

@epoberezkin love the idea, but the issue I struggled with was the need to have moment available at validation time as opposed to compile time. As far as I can tell, there would be no way to access the ajv instance itself at validation time using the inline method, or am I missing something?

@epoberezkin
Copy link
Author

epoberezkin commented Sep 5, 2016

Right, I was thinking about compilation time, where it's it.self :) But it's still available in inline keywords at validation time as self - I will add it to docs. In this case you don't even need the version to be 4.6.0+ - the instance is self from a long time ago, definitely before 2.0.0

@cludden cludden closed this as completed in 4917b1f Sep 6, 2016
@cludden
Copy link
Owner

cludden commented Sep 7, 2016

did not know about that, thanks for the sharing

@epoberezkin
Copy link
Author

you're welcome. I think I may define some instance property where users can put their stuff to be certain it won't clash with any ajv stuff (like res.locals in express)... But in this particular case moment won't be there ever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants