class-o-mat
Version:
ALPHA VERSION ONLY: class-o-mats will help to create getter-setter functionality with validations that can be attached to a container class for easier coding. Some basic validations are included. class-o-mats also has the ability to store params as bloc
118 lines (94 loc) • 3.66 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; }; }();
var _class, _temp;
var _bunyan = require('bunyan');
var _bunyan2 = _interopRequireDefault(_bunyan);
var _types = require('../constants/types');
var _fieldOMat = require('./field-o-mat');
var _fieldOMat2 = _interopRequireDefault(_fieldOMat);
var _apiMethod = require('../prototype/api-method');
var _apiMethod2 = _interopRequireDefault(_apiMethod);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var log = _bunyan2.default.createLogger({ name: "ApiFieldOMat" });
/**
* This will allow a pre-determined type of field to
* be added at different points in the API as determined
* by the using author.
*/
var ApiMethodOMat = (_temp = _class = function () {
function ApiMethodOMat(parent) {
var method = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _types.NONE;
_classCallCheck(this, ApiMethodOMat);
this.TYPE = _types.API_METHOD_O_MAT;
this._params = {
parent: parent,
key: _types.NONE,
method: method
};
}
_createClass(ApiMethodOMat, [{
key: 'key',
value: function key() {
var _key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _types.NONE;
if (_key === _types.NONE) return this._params.key;
this._params.key = _key;
return this;
}
}, {
key: 'default',
value: function _default() {
return _types.NONE;
}
}, {
key: '$',
value: function $() {
return this._params.parent;
}
}, {
key: 'as',
value: function as(key) {
this._params.apiKey = key;
return this;
}
}, {
key: 'as$',
value: function as$(key) {
this.as(key).$();
}
}, {
key: 'method',
value: function method(_method) {
this._params.method = _method();
return this._params.fieldOMat;
}
}, {
key: 'addToClassMixins',
value: function addToClassMixins(mixins) {
var paramObjectKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '_params';
var _params = this._params,
apiKey = _params.apiKey,
method = _params.method,
parent = _params.parent;
if (typeof apiKey !== 'string') {
throw new Error('Cannot add method without apiKey to ' + parent.key());
}
if (typeof method !== 'function') {
throw new Error('Tried to add illegal method to ' + parent.key() + ' at ' + apiKey);
}
mixins[apiKey] = function () {
for (var _len = arguments.length, p = Array(_len), _key2 = 0; _key2 < _len; _key2++) {
p[_key2] = arguments[_key2];
}
return method.apply(this, p);
};
return mixins;
}
}]);
return ApiMethodOMat;
}(), _class.TYPE = _types.API_METHOD_O_MAT, _temp);
exports.default = ApiMethodOMat;
//# sourceMappingURL=api-method-o-mat.js.map