Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected async _render(): Promise {
const env = expect(this.env, 'Unexpected missing environment during render');
// Create the template context for the root `main` template, which just
// contains the array of component roots. Any property references in that
// template will be looked up from this object.
let self = (this._self = new UpdatableReference({ roots: this._roots }));
// Create an empty root scope.
let dynamicScope = new DefaultDynamicScope();
let builder = this.builder.getBuilder(env);
let templateIterator = await this.loader.getTemplateIterator(
this,
env,
builder,
dynamicScope,
self
);
try {
// Begin a new transaction. The transaction stores things like component
// lifecycle events so they can be flushed once rendering has completed.
env.begin();
'supports passing in an initial dynamic context'() {
let delegate = new AotRenderDelegate();
delegate.registerComponent('Basic', 'Basic', 'Locale', `{{-get-dynamic-var "locale"}}`);
let element = delegate.getInitialElement();
let dynamicScope = new DefaultDynamicScope({
locale: new ConstReference('en_US'),
});
delegate.renderComponent('Locale', {}, element, dynamicScope);
QUnit.assert.equal((element as Element).innerHTML, 'en_US');
}
}
options: SSRApplicationOptions
) {
const app = new Application(options);
try {
const env = app.lookup(`environment:/${app.rootName}/main/main`);
const element = createHTMLDocument().body;
const builder = new StringBuilder({ element }).getBuilder(env);
const templateIterator = await app.loader.getComponentTemplateIterator(
app,
env,
builder,
componentName,
convertOpaqueToReferenceDict(data),
new DefaultDynamicScope(convertOpaqueToReferenceDict(options[INTERNAL_DYNAMIC_SCOPE]))
);
env.begin();
await app.renderer.render(templateIterator);
env.commit();
stream.write(app.serializer.serializeChildren(element));
stream.end();
} catch (err) {
stream.emit('error', err);
}
}