I have a getValidators function which returns an object with validator methods:
export function getValidators() {
return {
required: (node, value, [mark='', falsy=[undefined, '']]) => {
const notValid = falsy.includes(value);
return setNotValid(node, notValid, mark);
},
// ... other validator functions ...
};
};
All the validator functions have three arguments: node, value and an array: args
I can run the validator function:
let validator = 'required';
let validators = getValidators()
let result = validators[validator](node, value, args);
But I like to run the modified validator function below using the arguments node and value from some outer scope:
export function getValidators() {
return {
required: ([mark='', falsy=[undefined, '']]) => {
const notValid = falsy.includes(value);
return setNotValid(node, notValid, mark);
},
// ...
};
};
And like to run it as shown below:
// ... node and value args passed in from outer scope ...?
let result = validators[validator](args);
Update: I cannot use getValidators(node, value) because getValidators will be called first to add additional validator functions.
let validators = getValidators();
validators[method] = aValidatorFunc;
.....
.....
function runValidators() {
.....
// use the updated validators instance to run the validators
for (let validator of .....) {
// node and value will change in this loop as well
...
let result = validators[validator](args);
}
...
}