| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f024be8 commit 41318e1
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -161,22 +161,18 @@ var Engine = function (_EventEmitter) { | |||
| 161 | 161 | }, { | |
| 162 | 162 | key: 'prioritizeRules', | |
| 163 | 163 | value: function prioritizeRules() { | |
| 164 | - var _this2 = this; | ||
| 165 | - | ||
| 166 | 164 | if (!this.prioritizedRules) { | |
| 167 | - (function () { | ||
| 168 | - var ruleSets = _this2.rules.reduce(function (sets, rule) { | ||
| 169 | - var priority = rule.priority; | ||
| 170 | - if (!sets[priority]) sets[priority] = []; | ||
| 171 | - sets[priority].push(rule); | ||
| 172 | - return sets; | ||
| 173 | - }, {}); | ||
| 174 | - _this2.prioritizedRules = Object.keys(ruleSets).sort(function (a, b) { | ||
| 175 | - return Number(a) > Number(b) ? -1 : 1; // order highest priority -> lowest | ||
| 176 | - }).map(function (priority) { | ||
| 177 | - return ruleSets[priority]; | ||
| 178 | - }); | ||
| 179 | - })(); | ||
| 165 | + var ruleSets = this.rules.reduce(function (sets, rule) { | ||
| 166 | + var priority = rule.priority; | ||
| 167 | + if (!sets[priority]) sets[priority] = []; | ||
| 168 | + sets[priority].push(rule); | ||
| 169 | + return sets; | ||
| 170 | + }, {}); | ||
| 171 | + this.prioritizedRules = Object.keys(ruleSets).sort(function (a, b) { | ||
| 172 | + return Number(a) > Number(b) ? -1 : 1; // order highest priority -> lowest | ||
| 173 | + }).map(function (priority) { | ||
| 174 | + return ruleSets[priority]; | ||
| 175 | + }); | ||
| 180 | 176 | } | |
| 181 | 177 | return this.prioritizedRules; | |
| 182 | 178 | } | |
@@ -217,25 +213,25 @@ var Engine = function (_EventEmitter) { | |||
| 217 | 213 | key: 'evaluateRules', | |
| 218 | 214 | value: function () { | |
| 219 | 215 | var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(ruleArray, almanac) { | |
| 220 | - var _this3 = this; | ||
| 216 | + var _this2 = this; | ||
| 221 | 217 | ||
| 222 | 218 | return regeneratorRuntime.wrap(function _callee$(_context) { | |
| 223 | 219 | while (1) { | |
| 224 | 220 | switch (_context.prev = _context.next) { | |
| 225 | 221 | case 0: | |
| 226 | 222 | return _context.abrupt('return', Promise.all(ruleArray.map(function (rule) { | |
| 227 | - if (_this3.status !== RUNNING) { | ||
| 228 | - debug('engine::run status:' + _this3.status + '; skipping remaining rules'); | ||
| 223 | + if (_this2.status !== RUNNING) { | ||
| 224 | + debug('engine::run status:' + _this2.status + '; skipping remaining rules'); | ||
| 229 | 225 | return; | |
| 230 | 226 | } | |
| 231 | 227 | return rule.evaluate(almanac).then(function (rulePasses) { | |
| 232 | 228 | debug('engine::run ruleResult:' + rulePasses); | |
| 233 | 229 | if (rulePasses) { | |
| 234 | - _this3.emit('success', rule.event, almanac); | ||
| 235 | - _this3.emit(rule.event.type, rule.event.params, _this3); | ||
| 230 | + _this2.emit('success', rule.event, almanac); | ||
| 231 | + _this2.emit(rule.event.type, rule.event.params, _this2); | ||
| 236 | 232 | almanac.factValue('success-events', { event: rule.event }); | |
| 237 | 233 | } | |
| 238 | - if (!rulePasses) _this3.emit('failure', rule, almanac); | ||
| 234 | + if (!rulePasses) _this2.emit('failure', rule, almanac); | ||
| 239 | 235 | }); | |
| 240 | 236 | }))); | |
| 241 | 237 | ||
@@ -265,7 +261,7 @@ var Engine = function (_EventEmitter) { | |||
| 265 | 261 | key: 'run', | |
| 266 | 262 | value: function () { | |
| 267 | 263 | var _ref2 = _asyncToGenerator(regeneratorRuntime.mark(function _callee2() { | |
| 268 | - var _this4 = this; | ||
| 264 | + var _this3 = this; | ||
| 269 | 265 | ||
| 270 | 266 | var runtimeFacts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | |
| 271 | 267 | var almanac, orderedSets, cursor; | |
@@ -286,12 +282,12 @@ var Engine = function (_EventEmitter) { | |||
| 286 | 282 | return _context2.abrupt('return', new Promise(function (resolve, reject) { | |
| 287 | 283 | orderedSets.map(function (set) { | |
| 288 | 284 | cursor = cursor.then(function () { | |
| 289 | - return _this4.evaluateRules(set, almanac); | ||
| 285 | + return _this3.evaluateRules(set, almanac); | ||
| 290 | 286 | }).catch(reject); | |
| 291 | 287 | return cursor; | |
| 292 | 288 | }); | |
| 293 | 289 | cursor.then(function () { | |
| 294 | - _this4.status = FINISHED; | ||
| 290 | + _this3.status = FINISHED; | ||
| 295 | 291 | debug('engine::run completed'); | |
| 296 | 292 | resolve(almanac.factValue('success-events')); | |
| 297 | 293 | }).catch(reject); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments