UNPKG

@girders-elements/core

Version:

Girders Elements is an architectural framework that assists with building data-driven apps with React or React Native.

45 lines (32 loc) 2.74 kB
'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 _immutable=require('immutable'); var _AbstractRegistry2=require('./AbstractRegistry');var _AbstractRegistry3=_interopRequireDefault(_AbstractRegistry2);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");}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call&&(typeof call==="object"||typeof call==="function")?call:self;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass;}var Registry=function(_AbstractRegistry){_inherits(Registry,_AbstractRegistry); function Registry(){_classCallCheck(this,Registry);var _this=_possibleConstructorReturn(this,(Registry.__proto__||Object.getPrototypeOf(Registry)).call(this)); _this._registry=new _immutable.Map();return _this; }_createClass(Registry,[{key:'register',value:function register( kind,element){ var adaptedKey=this._adaptKey(kind); this._registry=this._registry.set(adaptedKey,element); }},{key:'isEmpty',value:function isEmpty() { return this._registry.count()===0; }},{key:'reset',value:function reset() { this._registry=new _immutable.Map(); }},{key:'_adaptKey',value:function _adaptKey( key){ if(key instanceof _immutable.List){ return key; } if(Array.isArray(key)){ return(0,_immutable.List)(key); } return _immutable.List.of(key); }},{key:'_getInternal',value:function _getInternal( key){ return this._registry.get(key); }},{key:'_lessSpecificKey',value:function _lessSpecificKey( key){ return key.count()>0?key.butLast():undefined; }}]);return Registry;}(_AbstractRegistry3.default);exports.default=Registry;