Skip to content

Commit

Permalink
Fix deepEquals import in rjsf v5 (#464)
Browse files Browse the repository at this point in the history
* clone deepEquals impl form @rjsf/utils v5 beta
* stop relying on deepEquals presence in @rjsf/core/utils
* might cause backwards compatibility issues on older rjsf version as the deepEquals implementation is different to the new one, but all tests pass 🤷‍♂️
  • Loading branch information
ivarprudnikov authored Dec 15, 2022
1 parent 9cfd296 commit 930f982
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
25 changes: 18 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"mavarazy <mavarazy@gmail.com>",
"Aivaras Prudnikovas <ivar.prudnikov@gmail.com>"
],
"version": "1.4.0",
"version": "1.5.0",
"scripts": {
"build": "rimraf dist lib && npm run build:umd && npm run build:cjs && npm run build:es && npm run build:es:lib",
"build:umd": "cross-env NODE_ENV=production BABEL_ENV=umd webpack --config webpack.config.dist.js",
Expand Down Expand Up @@ -57,6 +57,7 @@
},
"dependencies": {
"deepcopy": "^2.0.0",
"lodash.isequalwith": "^4.4.0",
"selectn": "^1.1.2"
},
"devDependencies": {
Expand Down
5 changes: 1 addition & 4 deletions src/applyRules.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { toError } from './utils';
import { toError, deepEquals } from './utils';
import rulesRunner from './rulesRunner';

import { DEFAULT_ACTIONS } from './actions';
import validateAction from './actions/validateAction';
import env from './env';

const { utils } = require('@rjsf/core');
const { deepEquals } = utils;

/**
* Intended to be used internally through applyRules(...)
* but it also needs to be tested
Expand Down
3 changes: 1 addition & 2 deletions src/rulesRunner.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import execute from "./actions";
import deepcopy from "deepcopy";
const { utils } = require("@rjsf/core");
const { deepEquals } = utils;
import { deepEquals } from './utils';

function doRunRules(engine, formData, schema, uiSchema, extraActions = {}) {
let schemaCopy = deepcopy(schema);
Expand Down
18 changes: 18 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
import { extractRefSchema } from "json-rules-engine-simplified/lib/utils";
import env from "./env";
import isEqualWith from "lodash/isEqualWith";

/** Cloned from @rjsf/utils v5 to make it work in older rjsf versions
*
* @param a - The first element to compare
* @param b - The second element to compare
* @returns - True if the `a` and `b` are deeply equal, false otherwise
*/
export const deepEquals = (a, b) => {
return isEqualWith(a, b, (obj, other) => {
if (typeof obj === "function" && typeof other === "function") {
// Assume all functions are equivalent
// see https://github.com/rjsf-team/react-jsonschema-form/issues/255
return true;
}
return undefined; // fallback to default isEquals behavior
});
};

export const toArray = (field) => {
if (Array.isArray(field)) {
Expand Down

0 comments on commit 930f982

Please sign in to comment.