@metacell/geppetto-meta-core
Version:
The core functionality of geppetto-meta to build and simulate neuroscience data and models.
150 lines (143 loc) • 4.7 kB
JavaScript
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
/**
* The parent node from where all other nodes extend
*
* @module model/Node
* @author Jesus R. Martinez (jesus@metacell.us)
*/
var Model = /*#__PURE__*/function () {
function Model() {
_classCallCheck(this, Model);
this.name = "";
this.instancePath = "";
this.id = "";
this.domainType = "";
this._metaType = "";
this.aspectNode = null;
this.parent = null;
this.tags = null;
}
/**
* Gets the instance path of the node
*
* @command Node.getInstancePath()
* @returns {String} Instance path of this node
*/
return _createClass(Model, [{
key: "getInstancePath",
value: function getInstancePath() {
return this.instancePath;
}
/**
* Gets the name of the node
*
* @command Node.getName()
* @returns {String} Name of the node
*/
}, {
key: "getName",
value: function getName() {
return this.name;
}
}, {
key: "getAspectNode",
value: function getAspectNode() {
return this.aspectNode;
}
/**
* Sets the name of the node
*
* @command Node.setName()
*/
}, {
key: "setName",
value: function setName(newname) {
this.name = newname;
}
/**
* Get the id associated with node
*
* @command Node.getId()
* @returns {String} ID of node
*/
}, {
key: "getId",
value: function getId() {
return this.id;
}
}, {
key: "getDomainType",
value: function getDomainType() {
return this.domainType;
}
}, {
key: "setDomainType",
value: function setDomainType(newDomainType) {
this.domainType = newDomainType;
}
}, {
key: "setParent",
value: function setParent(parent) {
this.parent = parent;
}
}, {
key: "getParent",
value: function getParent() {
return this.parent;
}
/**
* Recursively collects all nodes matching the given predicate.
* @param {Function} predicate - Function to test each node.
* @param {Array} matches - Array to collect matched nodes.
* @returns {Array} List of matched nodes.
*/
}, {
key: "_all",
value: function _all(predicate) {
var matches = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
if (predicate(this)) {
matches.push(this);
}
if (typeof this.getChildren === "function") {
for (var _i = 0, _Object$values = Object.values(this.getChildren()); _i < _Object$values.length; _i++) {
var child = _Object$values[_i];
this._all.call(child, predicate, matches);
}
}
return matches;
}
/**
* Search inside a node for all the nodes of a specific domain type.
*
* @param {String} domainType - Domain type
* @returns {Array} List of Nodes
*/
}, {
key: "getSubNodesOfDomainType",
value: function getSubNodesOfDomainType(domainType) {
return this._all(function (n) {
return n.domainType === domainType;
});
}
/**
* Search inside a node for all the nodes of a specific meta type.
*
* @param {String} metaType - Meta Type
* @returns {Array} List of Nodes
*/
}, {
key: "getSubNodesOfMetaType",
value: function getSubNodesOfMetaType(metaType) {
return this._all(function (n) {
return n._metaType === metaType;
});
}
}]);
}();
;
export default Model;