Skip to content

Commit

Permalink
compile validators
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomociti committed Jun 16, 2024
1 parent bc26f78 commit b3c5404
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/shapes-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,12 @@ class Constraint {
}

get validationFunction() {
return this.shape.isPropertyShape
if (this.compiledFunction) return this.compiledFunction
const func = this.shape.isPropertyShape
? this.component.propertyValidationFunction
: this.component.nodeValidationFunction
this.compiledFunction = func.compile(this)
return this.compiledFunction
}

get isValidationFunctionGeneric() {
Expand Down
2 changes: 1 addition & 1 deletion src/validation-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class ValidationEngine {
const { sh } = this.context.ns

this.recordErrorsLevel++
const validationOutput = constraint.validationFunction.execute(focusNode, valueNode, constraint)
const validationOutput = constraint.validationFunction.execute(focusNode, valueNode)

const validationResults = Array.isArray(validationOutput) ? validationOutput : [validationOutput]
const results = validationResults
Expand Down
9 changes: 6 additions & 3 deletions src/validation-function.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ class ValidationFunction {
this.func = func
}

execute(focusNode, valueNode, constraint) {
const compiled = this.func.apply(globalObject, [this.context, constraint])
return compiled.apply(globalObject, [this.context, focusNode, valueNode])
compile(constraint) {
return new ValidationFunction(this.context, this.funcName, this.func.apply(globalObject, [this.context, constraint]))
}

execute(focusNode, valueNode) {
return this.func.apply(globalObject, [this.context, focusNode, valueNode])
}
}

Expand Down

0 comments on commit b3c5404

Please sign in to comment.