dmn-js-decision-table-custom-z
Version:
A decision table view for dmn-js
72 lines (55 loc) • 1.89 kB
JavaScript
import { forEach } from 'min-dash';
import { elementToString } from './Util';
export default function TableTreeWalker(handler, options) {
function visit(element, ctx, definitions) {
var gfx = element.gfx; // avoid multiple rendering of elements
if (gfx) {
throw new Error("already rendered ".concat(elementToString(element)));
} // call handler
return handler.element(element, ctx, definitions);
}
function visitTable(element) {
return handler.table(element);
} // Semantic handling //////////////////////
function handleDecision(decision) {
if (!decision.id) {
decision.id = 'decision';
}
var table = decision.decisionLogic;
if (table) {
if (!table.output) {
throw new Error("missing output for ".concat(elementToString(table)));
}
var ctx = visitTable(table);
if (table.input) {
handleClauses(table.input, ctx, table);
}
handleClauses(table.output, ctx, table); // if any input or output clauses (columns) were added
// make sure that for each rule the according input/output entry is created
handleRules(table.rule, ctx, table);
} else {
throw new Error("no table for ".concat(elementToString(decision)));
}
}
function handleClauses(clauses, context, definitions) {
forEach(clauses, function (e) {
visit(e, context, definitions);
});
}
function handleRules(rules, context, definitions) {
forEach(rules, function (e) {
visit(e, context, definitions);
handleEntry(e.inputEntry, e);
handleEntry(e.outputEntry, e);
});
}
function handleEntry(entry, context, definitions) {
forEach(entry, function (e) {
visit(e, context, definitions);
});
} // API //////////////////////
return {
handleDecision: handleDecision
};
}
//# sourceMappingURL=TableTreeWalker.js.map