@girders-elements/core
Version:
Girders Elements is an architectural framework that assists with building data-driven apps with React or React Native.
56 lines (32 loc) • 2.94 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:true});exports.
enricher=enricher;var _ramda=require('ramda');var _ramda2=_interopRequireDefault(_ramda);var _util=require('../impl/util');var _data=require('../data');var data=_interopRequireWildcard(_data);var _zip=require('../zip');var zip=_interopRequireWildcard(_zip);function _interopRequireWildcard(obj){if(obj&&obj.__esModule){return obj;}else{var newObj={};if(obj!=null){for(var key in obj){if(Object.prototype.hasOwnProperty.call(obj,key))newObj[key]=obj[key];}}newObj.default=obj;return newObj;}}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function enricher(config){var _this=this;var
registry=config.registry,elementZipper=config.elementZipper;
if(registry.isEmpty())return function _callee(el){var context=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return regeneratorRuntime.async(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:return _context.abrupt('return',el);case 1:case'end':return _context.stop();}}},null,_this);};
var elementEnricher=(0,_util.memoize)(function(kind){
var enrichers=registry.get(kind);
return enrichers.isEmpty()?
null:
enrichers.reduce(
function(f,g){return function(x,context){return(
Promise.resolve(f(x,context)).then(function(x){return g(x,context);}));};},
function(x){return Promise.resolve(x);});
});
function postWalk(loc,context){var changedChildren,changedValue,elEnricher,_changedValue;return regeneratorRuntime.async(function postWalk$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:if(!
zip.canGoDown(loc)){_context2.next=6;break;}_context2.next=3;return regeneratorRuntime.awrap(
Promise.all(
data.flow(
zip.getChildren(loc),
_ramda2.default.map(_ramda2.default.pipe(elementZipper,function(loc){return postWalk(loc,context);})))));case 3:changedChildren=_context2.sent;
changedValue=zip.makeItem(
loc,
zip.value(loc),
_ramda2.default.map(zip.value,changedChildren));
loc=zip.replace(changedValue,loc);case 6:
elEnricher=data.flow(loc,zip.value,data.kindOf,elementEnricher);if(!(
elEnricher!=null)){_context2.next=12;break;}_context2.next=10;return regeneratorRuntime.awrap(
elEnricher(zip.value(loc),context));case 10:_changedValue=_context2.sent;
loc=zip.replace(_changedValue,loc);case 12:return _context2.abrupt('return',
loc);case 13:case'end':return _context2.stop();}}},null,this);}
return function _callee2(el){var context=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return regeneratorRuntime.async(function _callee2$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:_context3.t0=
zip;_context3.next=3;return regeneratorRuntime.awrap(postWalk(elementZipper(el),context));case 3:_context3.t1=_context3.sent;return _context3.abrupt('return',_context3.t0.value.call(_context3.t0,_context3.t1));case 5:case'end':return _context3.stop();}}},null,_this);};
}