babelute
Version:
Internal Domain Specific (Multi)Modeling javascript framework
93 lines (74 loc) • 2.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
exports.createPragmatics = createPragmatics;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
// removed in production
/**
* Base class to provide homogeneous Pragmatics interface. You should never instanciate a Pragmatics directly with new. use {@link createPragmatics}.
*/
var Pragmatics = exports.Pragmatics = function () {
/**
* @param {Object} targets initial targets object
* @param {Object} pragmas pragmatics methods to add
*/
function Pragmatics(targets, pragmas) {
_classCallCheck(this, Pragmatics);
/**
* targets holder object
* @type {Object}
* @public
*/
this._targets = targets;
if (pragmas) this.addPragmas(pragmas);
}
/**
* add methods to pragmatics instance
* @param {Object} pragmas an object containing methods to add
*/
_createClass(Pragmatics, [{
key: 'addPragmas',
value: function addPragmas(pragmas) {
for (var i in pragmas) {
/**
* @ignore
*/
this[i] = pragmas[i];
}
}
/* istanbul ignore next */
/**
* the method used to output a babelute through this pragmatics instance
* @abstract
*/
}, {
key: '$output',
value: function $output() /* ... */{
// to be overridden
throw new Error('pragmatics.$output should be implemented in subclasses');
}
}]);
return Pragmatics;
}();
/**
* return a new Pragmatics instance. Do not forget to implement $output before usage.
* @param {Object} targets initial targets object
* @param {Object} pragmas pragmatics methods to add
* @return {Pragmatics} the Pragmatics instance
*/
/**
* Pragmatics Class : minimal abstract class for homogeneous pragmatics.
*
* This is the minimal contract that a pragmatics should satisfy.
*
* @author Gilles Coomans
* @licence MIT
* @copyright 2016-2017 Gilles Coomans
*/
function createPragmatics() {
var targets = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var pragmas = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return new Pragmatics(targets, pragmas);
}