@girders-elements/core
Version:
Girders Elements is an architectural framework that assists with building data-driven apps with React or React Native.
110 lines (72 loc) • 5.24 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:true});exports.chainMultivalueRegistries=exports.chainRegistries=exports.MultivalueRegistryChain=exports.RegistryChain=undefined;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 _ramda=require('ramda');var _ramda2=_interopRequireDefault(_ramda);
var _AbstractRegistry3=require('./AbstractRegistry');var _AbstractRegistry4=_interopRequireDefault(_AbstractRegistry3);
var _Registry=require('./Registry');var _Registry2=_interopRequireDefault(_Registry);
var _MultivalueRegistry=require('./MultivalueRegistry');var _MultivalueRegistry2=_interopRequireDefault(_MultivalueRegistry);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
RegistryChain=exports.RegistryChain=function(_AbstractRegistry){_inherits(RegistryChain,_AbstractRegistry);
function RegistryChain(fallback,primary){_classCallCheck(this,RegistryChain);var _this=_possibleConstructorReturn(this,(RegistryChain.__proto__||Object.getPrototypeOf(RegistryChain)).call(this));
_this._fallbackRegistry=fallback;
_this._primaryRegistry=primary;return _this;
}_createClass(RegistryChain,[{key:'register',value:function register()
{
throw new Error('This is a read-only registry');
}},{key:'reset',value:function reset()
{
throw new Error('This is a read-only registry');
}},{key:'get',value:function get(
key){
return this._getBySpecificity(key,true);
}},{key:'isEmpty',value:function isEmpty()
{
return this._primaryRegistry.isEmpty()&&this._fallbackRegistry.isEmpty();
}},{key:'_getInternal',value:function _getInternal(
key){
var val=this._primaryRegistry._getInternal(
this._primaryRegistry._adaptKey(key));
if(!val){
val=this._fallbackRegistry._getInternal(
this._fallbackRegistry._adaptKey(key));
}
return val;
}},{key:'_adaptKey',value:function _adaptKey(
key){
return this._primaryRegistry._adaptKey(key);
}},{key:'_lessSpecificKey',value:function _lessSpecificKey(
key){
return this._primaryRegistry._lessSpecificKey(
this._primaryRegistry._adaptKey(key));
}}]);return RegistryChain;}(_AbstractRegistry4.default);var
MultivalueRegistryChain=exports.MultivalueRegistryChain=function(_AbstractRegistry2){_inherits(MultivalueRegistryChain,_AbstractRegistry2);
function MultivalueRegistryChain(fallback,primary){_classCallCheck(this,MultivalueRegistryChain);var _this2=_possibleConstructorReturn(this,(MultivalueRegistryChain.__proto__||Object.getPrototypeOf(MultivalueRegistryChain)).call(this));
_this2._fallbackRegistry=fallback;
_this2._primaryRegistry=primary;return _this2;
}_createClass(MultivalueRegistryChain,[{key:'register',value:function register()
{
throw new Error('This is a read-only registry');
}},{key:'reset',value:function reset()
{
throw new Error('This is a read-only registry');
}},{key:'_getInternal',value:function _getInternal(
key){
return this._fallbackRegistry.
_getInternal(key).
concat(this._primaryRegistry._getInternal(key));
}},{key:'_adaptKey',value:function _adaptKey(
key){
return this._primaryRegistry._adaptKey(key);
}},{key:'_lessSpecificKey',value:function _lessSpecificKey(
key){
return this._primaryRegistry._lessSpecificKey(
this._primaryRegistry._adaptKey(key));
}}]);return MultivalueRegistryChain;}(_AbstractRegistry4.default);
MultivalueRegistryChain.prototype._getBySpecificity=
_MultivalueRegistry2.default.prototype._getBySpecificity;
MultivalueRegistryChain.prototype.isEmpty=RegistryChain.prototype.isEmpty;
var chain=function chain(Chain,Zero){return(
_ramda2.default.cond([
[function(a){return a.length===0;},_ramda2.default.always(null)],
[function(a){return a.length===1;},_ramda2.default.head],
[_ramda2.default.T,_ramda2.default.reduce(function(a,b){return new Chain(a,b);},new Zero())]]));};
var chainRegistries=exports.chainRegistries=chain(RegistryChain,_Registry2.default);
var chainMultivalueRegistries=exports.chainMultivalueRegistries=chain(
MultivalueRegistryChain,_MultivalueRegistry2.default);