jurassix / react-validation-mixin

Simple validation mixin (HoC) for React.
MIT License
283 stars 38 forks source link

Swapping out the validation strategy #23

Closed mponizil closed 9 years ago

mponizil commented 9 years ago

Hi there,

Very pleased with the simple and modular nature of this library. Thank you!

Perhaps I'm just being dense, but I can't find a way to swap out the validation strategy without modifying the source directly.

From https://github.com/jurassix/react-validation-mixin/issues/3#issuecomment-71263235:

Factory provides an abstraction for the validation engine. Joi is isolated inside the Factory and can easily be swapped out, with out the need to modify the Mixin. Mixin uses a generic interface to the Factory, which keeps the coupling loose.

Looking through the source, there doesn't seem to be a way to override JoiValidationStrategy besides modifying ValidationFactory directly. My project uses webpack, so I tried configuring an alias for ValidationFactory, but it seems aliasing a dependency of a node_modules lib isn't supported, or I just couldn't figure it out. Regardless, I believe this is something the library should handle.

Please forgive me if there's an obvious API I've overlooked, or let me know if one would be desired and I'd be happy to take a stab at a PR.

Cheers, Misha

jurassix commented 9 years ago

@mponizil there is no way to swap out the factory yet. I've got details in #14 about the next steps for adding this feature. The library was designed specifically to swap out validation engines, but that piece of the architecture hasn't been exposed to the users yet. I'm about a week out from fixing this issue in a major release. If you have another validation library you'd like to support please contribute the integration to this library when the latest major release is published. We currently have support for Joi and revalidator, all others are welcome.

mponizil commented 9 years ago

Ahh thanks for the heads up, I shoulda reviewed #14. My use-case is actually just for one-off validators for now (MyValidators.NAME, MyValidators.EMAIL) -- need to keep a small file size, but liked the conventions provided by this mixin should I need to scale later.

Will definitely stay tuned for this update. Thanks!

jurassix commented 9 years ago

@mponizil you can now write your own strategy as of 5.0

Documentation for 5.0

mponizil commented 9 years ago

Great stuff, thanks @jurassix !