-
Notifications
You must be signed in to change notification settings - Fork 10
Replace inheritance with factory based and support for validationConstraints (global object) #47
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
Conversation
Renamed formValidation as baseFormValidation.
…the same context.
lib/lcformvalidation.d.ts
Outdated
| (vm: any): ValidationResult; | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove space
lib/package.json
Outdated
| "phantomjs-prebuilt": "^2.1.7", | ||
| "rimraf": "^2.5.2", | ||
| "sinon": "^1.17.6", | ||
| "sinon-chai": "^2.8.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need sinon-chai
lib/lcformvalidation.d.ts
Outdated
| } | ||
| import { } from 'core-js'; | ||
|
|
||
| export class FormNameToFieldNameMapping { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we remove this class?
lib/lcformvalidation.d.ts
Outdated
| vmFieldName: string; | ||
| } | ||
|
|
||
| export class FieldValidation { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should remove this class too because this is an internal entity
lib/src/index.ts
Outdated
| import { createFormValidation } from './baseFormValidation'; | ||
|
|
||
| export { | ||
| FormNameToFieldNameMapping, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove here too
lib/src/baseFormValidation.ts
Outdated
|
|
||
| private parseValidationConstraints(validationConstraints: ValidationConstraints) { | ||
| if (validationConstraints && typeof validationConstraints === 'object') { | ||
| if (validationConstraints.hasOwnProperty('global') && validationConstraints.global instanceof Array) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why you use validationConstraints.hasOwnProperty('global')?
You can't use validationConstraints.global?
lib/src/baseFormValidation.ts
Outdated
| }); | ||
| } | ||
|
|
||
| validateField(vm: any, key: string, value: any, filter?: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before refactor, this method looks like: filter: any = consts.defaultFilter).
Do you remove default value unintentionally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ValidationEngine already does it. It's unnecessary to do this twice.
lib/lcformvalidation.d.ts
Outdated
| constructor(); | ||
| } | ||
|
|
||
| export interface IValidationEngine { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should remove this interface too because this is an internal interface
lib/src/validationEngine.ts
Outdated
| import { } from 'core-js'; | ||
| import { FormNameToFieldNameMapping, FormValidationResult, FieldValidationResult, FieldValidation } from "./entities"; | ||
| import { | ||
| FormNameToFieldNameMapping, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
…porting chai-as-promised (used by Karma).
lib/src/validationEngine.ts
Outdated
| } | ||
|
|
||
| validateGlobalFormValidations(vm: any): Array<Promise<FieldValidationResult>> { | ||
| validateGlobalFormValidations(vm: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pending to add returned type? Promise<FieldValidationResult>[]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to discuss here if we should declare it for functions that already returns that value, e.g:
function isNotNull(object: any): boolean {
return object !== null;
}
function giveMeAPromiseWIthFieldValidationResult(someData: any): Promise<ValidationResult> {
return new Promise((resolve, reject) => {
const validationResult = new FieldValidationResult();
// do some logic here
resolve(validationResult);
});
}
lib/src/validationsDispatcher.ts
Outdated
| import { } from 'core-js'; | ||
| import { FormNameToFieldNameMapping, FieldValidationResult } from './entities'; | ||
| import { | ||
| FormNameToFieldNameMapping, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
lib/src/entities.ts
Outdated
| @@ -1,12 +1,7 @@ | |||
| import { } from 'core-js'; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove?
No description provided.