Skip to content

Commit

Permalink
replace deepEquals to fast-deep-equal
Browse files Browse the repository at this point in the history
  • Loading branch information
igorbrasileiro committed Sep 9, 2024
1 parent 2857f42 commit c69d0a6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
9 changes: 5 additions & 4 deletions packages/utils/src/createSchemaUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import deepEquals from './deepEquals';
import fastDeepEqual from 'fast-deep-equal';

import {
ErrorSchema,
Experimental_DefaultFormStateBehavior,
Expand All @@ -14,9 +15,9 @@ import {
ValidatorType,
} from './types';
import {
getClosestMatchingOption,
getDefaultFormState,
getDisplayLabel,
getClosestMatchingOption,
getFirstMatchingOption,
getMatchingOption,
isFilesArray,
Expand Down Expand Up @@ -84,8 +85,8 @@ class SchemaUtils<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
}
return (
this.validator !== validator ||
!deepEquals(this.rootSchema, rootSchema) ||
!deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior)
!fastDeepEqual(this.rootSchema, rootSchema) ||
!fastDeepEqual(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior)
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/validator-ajv6/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Ajv, ErrorObject } from 'ajv';
import {
createErrorHandler,
CustomValidator,
deepEquals,
ErrorSchema,
ErrorTransformer,
FormContextType,
Expand All @@ -20,6 +19,7 @@ import {
ValidatorType,
withIdRefPrefix,
} from '@rjsf/utils';
import fastDeepEqual from 'fast-deep-equal';

import { CustomValidatorOptionsType } from './types';
import createAjvInstance from './createAjvInstance';
Expand Down Expand Up @@ -170,7 +170,7 @@ export default class AJV6Validator<T = any, S extends StrictRJSFSchema = RJSFSch
// else 'handleRootSchemaChange' should be called if the root schema changes so we don't have to remove and recompile the schema every run.
if (this.ajv.getSchema(ROOT_SCHEMA_PREFIX) === undefined) {
this.ajv.addSchema(rootSchema, ROOT_SCHEMA_PREFIX);
} else if (!deepEquals(rootSchema, this.ajv.getSchema(ROOT_SCHEMA_PREFIX)?.schema)) {
} else if (!fastDeepEqual(rootSchema, this.ajv.getSchema(ROOT_SCHEMA_PREFIX)?.schema)) {
this.ajv.removeSchema(rootSchemaId);
this.ajv.addSchema(rootSchema, rootSchemaId);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/validator-ajv8/src/validator.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Ajv, { ErrorObject, ValidateFunction } from 'ajv';
import {
CustomValidator,
deepEquals,
ErrorSchema,
ErrorTransformer,
FormContextType,
hashForSchema,
ID_KEY,
RJSFSchema,
ROOT_SCHEMA_PREFIX,
Expand All @@ -14,8 +14,8 @@ import {
ValidationData,
ValidatorType,
withIdRefPrefix,
hashForSchema,
} from '@rjsf/utils';
import fastDeepEqual from 'fast-deep-equal';

import { CustomValidatorOptionsType, Localizer } from './types';
import createAjvInstance from './createAjvInstance';
Expand Down Expand Up @@ -137,7 +137,7 @@ export default class AJV8Validator<T = any, S extends StrictRJSFSchema = RJSFSch
// else if the root schemas don't match, we should remove and add the root schema so we don't have to remove and recompile the schema every run.
if (this.ajv.getSchema(rootSchemaId) === undefined) {
this.ajv.addSchema(rootSchema, rootSchemaId);
} else if (!deepEquals(rootSchema, this.ajv.getSchema(rootSchemaId)?.schema)) {
} else if (!fastDeepEqual(rootSchema, this.ajv.getSchema(rootSchemaId)?.schema)) {
this.ajv.removeSchema(rootSchemaId);
this.ajv.addSchema(rootSchema, rootSchemaId);
}
Expand Down

0 comments on commit c69d0a6

Please sign in to comment.