UNPKG

ima

Version:

IMA.js framework for isomorphic javascript application

89 lines (68 loc) 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _GenericError = require("../error/GenericError"); var _GenericError2 = _interopRequireDefault(_GenericError); var _Execution = require("./Execution"); var _Execution2 = _interopRequireDefault(_Execution); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const CLASS_REGEX = /^\s*class\b/; /** * Basic implementation of the {@link Execution} interface. Provides the basic * functionality for appending and validating jobs. * * @abstract * @extends Execution */ class AbstractExecution extends _Execution2.default { constructor(jobs = []) { super(); this._jobs = jobs.filter(this._validateJob); } /** * @inheritDoc */ append(jobs) { if (!Array.isArray(jobs)) { jobs = [jobs]; } this._jobs = this._jobs.concat(jobs.filter(this._validateJob)); } /** * @inheritDoc */ execute() { throw new _GenericError2.default('The ima.execution.AbstractExecution.execute method is abstract ' + 'and must be overridden'); } /** * Return {@code true} if the given job can be executed * * @protected * @param {function(): Promise} job * @returns {boolean} */ _validateJob(job) { if (typeof job === 'function') { if (!CLASS_REGEX.test(job.toString())) { return true; } } if ($Debug) { console.warn('ima.execution.AbstractExecution: Given job is not a callable ' + 'function therefore it will be excluded from execution.', { job }); } return false; } } exports.default = AbstractExecution; typeof $IMA !== 'undefined' && $IMA !== null && $IMA.Loader && $IMA.Loader.register('ima/execution/AbstractExecution', [], function (_export, _context) { 'use strict'; return { setters: [], execute: function () { _export('default', exports.default); } }; });