marko
Version:
UI Components + streaming, async, high performance, HTML templating for Node.js and the browser.
87 lines (74 loc) • 2.22 kB
JavaScript
;
const ComponentDef = require("../../../runtime/components/ComponentDef");
var FLAG_WILL_RERENDER_IN_BROWSER = 1;
// var FLAG_HAS_RENDER_BODY = 2;
var FLAG_OLD_HYDRATE_NO_CREATE = 8;
module.exports = function beginComponent(
componentsContext,
component,
key,
ownerComponentDef,
isSplitComponent,
isImplicitComponent,
existingComponentDef)
{
var componentId = component.id;
// existingComponentDef is only here to allow binding a conditional
// widget. It should be removed when the legacy compat layer is removed.
var componentDef =
existingComponentDef || (
componentsContext.o_ = new ComponentDef(
component,
componentId,
componentsContext
));
var ownerIsRenderBoundary =
ownerComponentDef && ownerComponentDef.t_;
var ownerWillRerender =
ownerComponentDef &&
ownerComponentDef.u_ & FLAG_WILL_RERENDER_IN_BROWSER;
// On the server
if (ownerWillRerender && !componentsContext.v_) {
componentDef.u_ |= FLAG_WILL_RERENDER_IN_BROWSER;
componentDef._wrr = true;
return componentDef;
}
if (componentsContext.w_) {
componentsContext.w_ = false;
isSplitComponent = false;
} else if (isImplicitComponent === true) {
// We don't mount implicit components rendered on the server
// unless the implicit component is nested within a UI component
// that will re-render in the browser
return componentDef;
}
componentsContext.b_.push(componentDef);
let out = componentsContext.r_;
let runtimeId = out.global.runtimeId;
componentDef.t_ = true;
componentDef.x_ = componentsContext.v_;
if (isSplitComponent === false && out.global.noBrowserRerender !== true) {
componentDef.u_ |= FLAG_WILL_RERENDER_IN_BROWSER;
componentDef._wrr = true;
componentsContext.v_ = false;
}
if (out.global.oldHydrateNoCreate === true) {
componentDef.u_ |= FLAG_OLD_HYDRATE_NO_CREATE;
}
if ((ownerIsRenderBoundary || ownerWillRerender) && key != null) {
out.w(
"<!--" +
runtimeId +
"^" +
componentId +
" " +
ownerComponentDef.id +
" " +
key +
"-->"
);
} else {
out.w("<!--" + runtimeId + "#" + componentId + "-->");
}
return componentDef;
};