An affected attribute is referenced by an effect and receives the value determined or changed by a business rule. In an Increment Effect, the attribute reference identifies the numeric attribute being incremented. section 14.1.3
Implementation concerns include:
- Initialize the affected attribute before applying increments; a discount attribute therefore starts at 0%. section 14.2.2
- Require an initial value rather than a computed value when an increment effect references the attribute. section 14.2.2
- Collect affected attributes by inspecting each rule consequence and deduplicating the referenced attributes. section 14.3.1
Accumulating a discount
Set `let discount = 0` before executing the business rules. Each applicable Increment Effect adds its operand to the referenced discount attribute, leaving the variable with the value determined by the rules. section 14.2.2
Listing 14.27 Determining attributes affected by a rule’s consequence
const affectedAttributesInConsequence = #1
(consequence) => {
if (!isAstObject(consequence)) { #2
return []
}
const { settings } = consequence
switch (consequence.concept) {
case "Increment Effect":
return referencedAttributesIn( #3
settings["attribute reference"])
default: {
console.warn(`affectedAttributesInConsequence(..)
doesn't handle instances of the
concept "${consequence.concept}" #4
- returning []`)
return [] #5
}
}
}
module.exports.affectedAttributesInConsequence =
affectedAttributesInConsequence
Inspect how a consequence exposes its referenced attributes, then follow the query that aggregates affected attributes across business rules. section 14.3.1
