UNPKG

@code-o-mat/globals

Version:

Abstract Package to support CodeOMat series of apps.

186 lines (152 loc) 5.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _v = _interopRequireDefault(require("uuid/v4")); var _values = require("./constants/values"); var _types = require("./constants/types"); var _oMatTypes = require("./assertions/o-mat-types"); var _jsTypes = require("./assertions/js-types"); var _cache = _interopRequireDefault(require("./caches/cache")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return right[Symbol.hasInstance](left); } else { return left instanceof right; } } function _classCallCheck(instance, Constructor) { if (!_instanceof(instance, Constructor)) { throw new TypeError("Cannot call a class as a 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); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } var OMat = /*#__PURE__*/ function () { function OMat() { var source = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _values.NONE; _classCallCheck(this, OMat); Object.defineProperty(this, "APP", { configurable: true, enumerable: true, writable: true, value: _types.CODE_O_MAT }); Object.defineProperty(this, "FAMILY", { configurable: true, enumerable: true, writable: true, value: _types.O_MAT }); Object.defineProperty(this, "TYPE", { configurable: true, enumerable: true, writable: true, value: _types.O_MAT }); this[_values.PROPS] = new _cache.default({ source: source, name: _values.NONE, UID: (0, _v.default)(), Cache: _cache.default }); } /** * creates a clone with a new name and new UID * @param {string|symbol} name * @return {OMat} The new OMat */ _createClass(OMat, [{ key: "again", value: function again() { var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _values.NONE; (0, _jsTypes.assertIsKey)(name); var props = this[_values.PROPS].clone(); props.merge({ name: name, UID: (0, _v.default)() }); return new this.constructor().props(); } /** * creates a clone with a new UID but the same name. * @return {OMat} the new OMat */ }, { key: "clone", value: function clone() { return this.again(this.name()); } /** * Getter / Setter for name. * @param {string|symbol} name [description] * @return {[type]} [description] */ }, { key: "name", value: function name() { var _name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _values.NONE; if (_name === _values.NONE) return this[_values.PROPS].get('name'); (0, _jsTypes.assertIsKey)(_name); this[_values.PROPS].set('name', _name); return this; } /** * accessor for the properties cache * if called with no arguments, will return the properties cache. * if called with a javascript object, will create a new Properties * cache from this object. * * This should not be used without considering * that the UID of the OMat in the properties object * will be eliminated. * @param {object} newProps * @return {props cache | OMat} */ }, { key: "props", value: function props() { var newProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _values.NONE; if (newProps === _values.NONE) return this[_values.PROPS]; var Cache = this[_values.PROPS].get('Cache'); this[_values.PROPS] = new Cache(newProps); return this; } /** * getter setter accessor for source */ }, { key: "source", value: function source() { var _source = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _values.NONE; if (_source === _values.NONE) return this[_values.PROPS].get('source'); (0, _oMatTypes.assertIsOMat)(_source); this[_values.PROPS].set('source', _source); return this; } /** * getter for uid */ }, { key: "uid", value: function uid() { return this[_values.PROPS].get('UID'); ; } }]); return OMat; }(); Object.defineProperty(OMat, "APP", { configurable: true, enumerable: true, writable: true, value: _types.CODE_O_MAT }); Object.defineProperty(OMat, "FAMILY", { configurable: true, enumerable: true, writable: true, value: _types.O_MAT }); Object.defineProperty(OMat, "TYPE", { configurable: true, enumerable: true, writable: true, value: _types.O_MAT }); var _default = OMat; exports.default = _default;