@leafage/renderer
Version:
The React Server Side Render Framework
65 lines (61 loc) • 2.34 kB
JavaScript
/**
* @leafage/renderer v1.3.2
*
* Copyright (c) Leafage.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
;
var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js');
var toolkit = require('@leafage/toolkit');
var renderRoutePreset = function renderRoutePreset(ctx) {
ctx.renderRoute = /*#__PURE__*/function () {
var _ref = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee(req, res) {
var resource, _yield$imports$import, appLoader, _yield$imports$import2, viewLoader, loaderContext, appProps, viewProps, props;
return _rollupPluginBabelHelpers.regenerator().w(function (_context) {
while (1) switch (_context.n) {
case 0:
resource = ctx.findResource(req.pathname);
if (resource) {
_context.n = 1;
break;
}
return _context.a(2);
case 1:
req.params = resource.params;
_context.n = 2;
return toolkit.imports.importServerModule('App', ctx.options);
case 2:
_yield$imports$import = _context.v;
appLoader = _yield$imports$import.loader;
_context.n = 3;
return toolkit.imports.importServerModule(resource.view, ctx.options);
case 3:
_yield$imports$import2 = _context.v;
viewLoader = _yield$imports$import2.loader;
loaderContext = {
req: req,
res: res
};
_context.n = 4;
return appLoader === null || appLoader === void 0 ? void 0 : appLoader(loaderContext);
case 4:
appProps = _context.v;
_context.n = 5;
return viewLoader === null || viewLoader === void 0 ? void 0 : viewLoader(loaderContext);
case 5:
viewProps = _context.v;
props = toolkit.utils.mergeProps(appProps, viewProps);
return _context.a(2, ctx.render(resource.view, props));
}
}, _callee);
}));
return function (_x, _x2) {
return _ref.apply(this, arguments);
};
}();
};
exports.renderRoutePreset = renderRoutePreset;