How to use the @glimmer/runtime.DefaultDynamicScope function in @glimmer/runtime

To help you get started, we’ve selected a few @glimmer/runtime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github glimmerjs / glimmer.js / packages / @glimmer / application / src / application.ts View on Github external
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();
github glimmerjs / glimmer-vm / packages / @glimmer / integration-tests / lib / suites / entry-point.ts View on Github external
'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');
  }
}
github glimmerjs / glimmer.js / packages / @glimmer / ssr / src / application.ts View on Github external
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);
    }
  }