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
169 lines (136 loc) • 5.62 kB
JavaScript
'use strict';
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 _bunyan = require('bunyan');
var _bunyan2 = _interopRequireDefault(_bunyan);
var _types = require('../constants/types');
var _fieldFunctions = require('../methods/field-functions');
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: "AccessorsOMat" });
var _AccessorsOMat = function () {
function _AccessorsOMat() {
_classCallCheck(this, _AccessorsOMat);
this.TYPE = _types.ACCESSORS_O_MAT;
}
_createClass(_AccessorsOMat, [{
key: 'getter',
/**
* sets this field to become a simple getter in the target class
* ( NOTE: for performance reasons,
* Getter function operates as a function with no parameters,
* not as a traditional getter field )
* @return {FieldOMat} this
*/
value: function getter() {
var _default = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _types.NONE;
this._params.accessorGetter = _fieldFunctions.getter;
this.default(_default);
return this;
}
/**
* sets this field to become a simple setter in the target class
* ( NOTE: for performance reasons,
* Setter function operates as a function with a value parameter,
* not a
* @return {FieldOMat} this
*/
}, {
key: 'setter',
value: function setter() {
var _default = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _types.NONE;
this._params.accessorGetter = _fieldFunctions.setter;
this.default(_default);
return this;
}
}, {
key: 'staticSetter',
value: function staticSetter() {
var staticValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _types.NONE;
this._params.accessorGetter = _fieldFunctions.staticSetter;
this._params.staticValue = staticValue;
return this;
}
/**
* sets this field to become a getter or setter depending upon if a
* value argument is passed in.
* If [fieldName]() is called, this is a getter,
* if [fieldName](someValue) is called, this sets the value to someValue
* NOTE: This type of function uses an internal symbol to represent a null
* value, which means that passing in falsey values ( false, 0, -x, null)
* will SET that falsey value as a parameter.
* @return {FieldOMat} this
*/
}, {
key: 'getterSetter',
value: function getterSetter() {
var _default = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _types.NONE;
this._params.accessorGetter = _fieldFunctions.getterSetter;
this.default(_default);
return this;
}
/**
* sets this field to become a getter or setter depending upon if a
* value argument is passed in.. However, provides an option to trigger
* either an error or a fail gracefully when setting
* to ensure that null values return a chain.
* If [fieldName]() is called, this is a getter,
* if [fieldName](someValue) is called, this sets the value to someValue
* NOTE: This type of function uses an internal symbol to represent a null
* value, which means that passing in falsey values ( false, 0, -x, null)
* will SET that falsey value as a parameter.
* @return {FieldOMat} this
*/
}, {
key: 'getterSetterSafe',
value: function getterSetterSafe() {
var _default = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _types.NONE;
this._params.accessorGetter = _fieldFunctions.getterSetterSafe;
this.default(_default);
return this;
}
/**
* setter that will toggle true or false.
* @return {FieldOMat} this
*/
}, {
key: 'toggler',
value: function toggler() {
var _default = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
this._params.accessorGetter = _fieldFunctions.toggler;
this.default(_default);
return this;
}
/**
* A Setter that will return the original value.
* @return {FieldOMat} this
*/
}, {
key: 'swapper',
value: function swapper() {
var _default = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _types.NONE;
this._params.accessorGetter = _fieldFunctions.swapper;
this.default(_default);
return this;
}
}, {
key: 'queue',
value: function queue() {
this._params.isStack = false;
this._params.isQueue = true;
return this;
}
}, {
key: 'stack',
value: function stack() {
this._params.isQueue = false;
this._params.isStack = true;
return this;
}
}]);
return _AccessorsOMat;
}();
exports.default = _AccessorsOMat;
//# sourceMappingURL=_accessors-o-mat.js.map