marko/components/legacy/defineRenderer-legacy.js
2017-02-20 16:30:16 -07:00

37 lines
1.1 KiB
JavaScript

var marko = require('../../');
var makeRenderable = require('../../runtime/renderable');
module.exports = function defineRenderer(renderingLogic) {
var renderer = renderingLogic.renderer;
if (renderer && renderer.$__isRenderer) {
return renderer;
}
var template = renderingLogic.template;
if (typeof template === 'string') {
template = marko.load(template);
}
if (!renderer) {
// Create a renderer function that takes care of translating
// the input properties to a view state. Also, this renderer
// takes care of re-using existing components.
renderer = function renderer(input, out) {
// Render the template associated with the component using the final template
// data that we constructed
template._(input, out, renderingLogic);
};
}
renderer.$__isRenderer = true;
renderer.createOut = template ? template.createOut : renderingLogic.createOut;
renderer.template = template;
makeRenderable(renderer, renderer);
return renderer;
};