-
Notifications
You must be signed in to change notification settings - Fork 38
Keep validation result in state #2
Comments
Thanks for the report. Yup, I've been playing with different options to correct the current performance overhead of validating single fields verse validating all fields. I like the idea of caching the result set; I don't want to override any of the component lifecycle methods unless absolutely necessary. |
I'ts common scenario to provide self-validation (in terms of required properties, not that validation) in If you just cache result set with some |
I didn't know that mixin's chained; good information. |
This is resolved and published to npm in version 2.1.0 I'm maintaining a cache of validation results and invalidating that cache automatically during the ComponentWillUpdate lifecycle. I've also exposed a manual clearValidations() api if you need to force a revalidation during a render cycle. Validations are also lazily initialized; we only validate on the first call to isValid or getValidationsMessages. This now ensures only the first call has a processing overhead and all subsequent render calls are pulling from cache |
Ah, ok. I always look into Releases tab and it somehow misses last ones. |
Fixed |
I think I have a strong argument for Besides of validation error messages there are other errors. Like "email is already used". If library uses I think your consideration in avoiding state usage is to prevent potential conflicts. Keys with the same names may override which should lead to debugging hell... Well, luckily no. React is smart enough to prevent this. See http://stackoverflow.com/questions/23872374/is-initialstate-in-a-mixin-merged-with-initialstate-in-a-component
|
Thanks for the argument and research. I agree with you on using state to store the errors, caching on 'this' didn't seem right for React. I'll correct this in the next release. |
fixed in version 3.0.0 validation errors are now stored on the components state: |
Wow, You're blazingly fast :) |
Currently, validation may be called multiple times with the same data. For example,
isValid
may be called on submit andgetValidationMessages(<field-name>)
may be called n times for each field to get and render error messages.Instead of returning validation messages it's probably better to keep them in state.
This link may help: Reference implementation
The text was updated successfully, but these errors were encountered: