Skip to content

Commit

Permalink
Merge pull request #728 from smartxworks/fix/validation-trait
Browse files Browse the repository at this point in the history
feat(Validation): add the default values for the props and params
  • Loading branch information
tanbowensg committed Feb 20, 2024
2 parents 78a7fa7 + 5902e34 commit a9cf6f9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/runtime/src/traits/core/Validation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,15 @@ export default implementRuntimeTrait({
const resultMap = new Map();

return props => {
const { validators, componentId, subscribeMethods, mergeState } = props;
const { validators = [], componentId, subscribeMethods, mergeState } = props;
const validatorMap = validators.reduce((result, validator) => {
result[validator.name] = validator;

return result;
}, {} as Record<string, Static<typeof ValidatorSpec>>);

function setErrors({
errorsMap,
errorsMap = {},
}: {
errorsMap: Record<string, Static<typeof ErrorSpec>[]>;
}) {
Expand All @@ -311,7 +311,7 @@ export default implementRuntimeTrait({
});
resultMap.set(componentId, validatedResult);
}
function validateFields({ names }: { names: string[] }) {
function validateFields({ names = [] }: { names: string[] }) {
const validatedResult = names
.filter(name => validatorMap[name])
.map(name => {
Expand Down Expand Up @@ -362,7 +362,7 @@ export default implementRuntimeTrait({
function validateAllFields() {
validateFields({ names: validators.map(({ name }) => name) });
}
function clearErrors({ names }: { names: string[] }) {
function clearErrors({ names = [] }: { names: string[] }) {
setErrors({
errorsMap: names.reduce((result: Record<string, []>, name) => {
result[name] = [];
Expand Down

0 comments on commit a9cf6f9

Please sign in to comment.