@girders-elements/core
Version:
Girders Elements is an architectural framework that assists with building data-driven apps with React or React Native.
54 lines (43 loc) • 3.18 kB
JavaScript
;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 _AbstractRegistry2=require('./AbstractRegistry');var _AbstractRegistry3=_interopRequireDefault(_AbstractRegistry2);
var _immutable=require('immutable');
var _ramda=require('ramda');var _ramda2=_interopRequireDefault(_ramda);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
PatternRegistry=function(_AbstractRegistry){_inherits(PatternRegistry,_AbstractRegistry);
function PatternRegistry(){_classCallCheck(this,PatternRegistry);var _this=_possibleConstructorReturn(this,(PatternRegistry.__proto__||Object.getPrototypeOf(PatternRegistry)).call(this));
_this._registry=new _immutable.List();return _this;
}_createClass(PatternRegistry,[{key:'register',value:function register(
key,value){
var pattern=void 0;
if(typeof key==='function'){
pattern=_immutable.List.of(key,value);
}else if(key instanceof RegExp){
var regexp=key;
pattern=_immutable.List.of(regexp.test.bind(regexp),value);
}else{
pattern=_immutable.List.of(equals(key),value);
}
this._registry=this._registry.push(pattern);
}},{key:'isEmpty',value:function isEmpty()
{
return this._registry.count()===0;
}},{key:'reset',value:function reset()
{
this._registry=new _immutable.List();
}},{key:'_adaptKey',value:function _adaptKey(
key){
return key;
}},{key:'_getInternal',value:function _getInternal(
key){
var result=this._registry.find(function(r){return r.get(0)(key);});
if(result){
return result.get(1);
}
}},{key:'_lessSpecificKey',value:function _lessSpecificKey()
{
return null;
}}]);return PatternRegistry;}(_AbstractRegistry3.default);exports.default=PatternRegistry;
var equals=_ramda2.default.curryN(
2,
_ramda2.default.ifElse(
function(a,b){return _immutable.Iterable.isIterable(a)&&_immutable.Iterable.isIterable(b);},_immutable.is,
_ramda2.default.equals));