MCPcopy
hub / github.com/CacheControl/json-rules-engine / prioritizeRules

Method prioritizeRules

src/engine.js:197–210  ·  view source on GitHub ↗

* Iterates over the engine rules, organizing them by highest -> lowest priority * @return {Rule[][]} two dimensional array of Rules. * Each outer array element represents a single priority(integer). Inner array is * all rules with that priority.

()

Source from the content-addressed store, hash-verified

195 * all rules with that priority.
196 */
197 prioritizeRules () {
198 if (!this.prioritizedRules) {
199 const ruleSets = this.rules.reduce((sets, rule) => {
200 const priority = rule.priority
201 if (!sets[priority]) sets[priority] = []
202 sets[priority].push(rule)
203 return sets
204 }, {})
205 this.prioritizedRules = Object.keys(ruleSets).sort((a, b) => {
206 return Number(a) > Number(b) ? -1 : 1 // order highest priority -> lowest
207 }).map((priority) => ruleSets[priority])
208 }
209 return this.prioritizedRules
210 }
211
212 /**
213 * Stops the rules engine from running the next priority set of Rules. All remaining rules will be resolved as undefined,

Callers 3

runMethod · 0.95
setupFunction · 0.80

Calls

no outgoing calls

Tested by 1

setupFunction · 0.64