+
+ )
}
const ResultLine = styled.div`
diff --git a/publicodes/core/source/index.ts b/publicodes/core/source/index.ts
index 1ba321345..318962f52 100644
--- a/publicodes/core/source/index.ts
+++ b/publicodes/core/source/index.ts
@@ -189,25 +189,16 @@ export default class Engine {
}
/**
- This function allows smother migration to the new Engine API
+ This function allows to mimic the old 'isApplicable' property on evaluatedRules
It will be deprecated when applicability will be encoded as a Literal type
- Prefer the use of `engine.evaluate(engine.getRule(dottedName))`
*/
-export function UNSAFE_evaluateRule(
+export function UNSAFE_isNotApplicable(
engine: Engine,
- dottedName: DottedName,
- modifiers: Object = {}
-): EvaluatedRule {
- const evaluation = simplifyNodeUnit(
- engine.evaluate({ valeur: dottedName, ...modifiers })
- )
- const rule = engine.getRule(dottedName) as RuleNode & {
- dottedName: DottedName
- }
-
- // HACK while waiting for applicability to have its own type
- const isNotApplicable = reduceAST(
+ dottedName: DottedName
+): boolean {
+ const rule = engine.getRule(dottedName)
+ return reduceAST(
function (isNotApplicable, node, fn) {
if (isNotApplicable) return isNotApplicable
if (!('nodeValue' in node)) {
@@ -235,10 +226,30 @@ export function UNSAFE_evaluateRule(
}
},
false,
- evaluation
+ engine.evaluate(dottedName)
)
+}
+
+/**
+ This function allows smother migration to the new Engine API
+
+ It will be deprecated when applicability will be encoded as a Literal type
+ Prefer the use of `engine.evaluate(engine.getRule(dottedName))`
+*/
+export function UNSAFE_evaluateRule(
+ engine: Engine,
+ dottedName: DottedName,
+ modifiers: Object = {}
+): EvaluatedRule {
+ const evaluation = simplifyNodeUnit(
+ engine.evaluate({ valeur: dottedName, ...modifiers })
+ )
+ const rule = engine.getRule(dottedName) as RuleNode & {
+ dottedName: DottedName
+ }
+
return {
- isNotApplicable,
+ isNotApplicable: UNSAFE_isNotApplicable(engine, dottedName),
...rule.rawNode,
...rule,
...evaluation,