Skip to content

Commit

Permalink
Properly export the Evaluator.
Browse files Browse the repository at this point in the history
  • Loading branch information
travist committed Apr 23, 2024
1 parent fbeae9a commit 33febf2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
24 changes: 10 additions & 14 deletions src/utils/Evaluator.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import _ from 'lodash';
import stringHash from 'string-hash';
import { Evaluator as CoreEvaluator } from '@formio/core/utils';
const Evaluator = {
noeval: false,
protectedEval: false, // This property can be customized only by plugins
cache: {},
templateSettings: CoreEvaluator.templateSettings,
evaluator: CoreEvaluator.evaluator,
template(template, hash) {

export class Evaluator extends CoreEvaluator {
static cache = {};
static protectedEval = false;
static template(template, hash) {
hash = hash || stringHash(template);
if (Evaluator.cache[hash]) {
return Evaluator.cache[hash];
Expand All @@ -20,8 +18,8 @@ const Evaluator = {
catch (err) {
console.warn('Error while processing template', err, template);
}
},
interpolate(rawTemplate, data, _options) {
}
static interpolate(rawTemplate, data, _options) {
// Ensure reverse compatability.
const options = _.isObject(_options) ? _options : { noeval: _options };
if (typeof rawTemplate === 'function') {
Expand Down Expand Up @@ -52,16 +50,14 @@ const Evaluator = {
}
}
return template;
},
evaluate(func, args) {
}
static evaluate(func, args) {
return Array.isArray(args) ? func(...args) : func(args);
}
};
}

Evaluator.registerEvaluator = (evaluator) => {
Object.keys(evaluator).forEach((key) => {
Evaluator[key] = evaluator[key];
});
};

export default Evaluator;
2 changes: 1 addition & 1 deletion src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import jtz from 'jstimezonedetect';
import { lodashOperators } from './jsonlogic/operators';
import dompurify from 'dompurify';
import { getValue } from './formUtils';
import Evaluator from './Evaluator';
import { Evaluator } from './Evaluator';
import ConditionOperators from './conditionOperators';
const interpolate = Evaluator.interpolate;
const { fetch } = fetchPonyfill({
Expand Down

0 comments on commit 33febf2

Please sign in to comment.