glimmerjs / glimmer-experimental

A set of experimental high-level APIs built on Glimmer.js
https://glimmerjs.github.io/glimmer-experimental/
59 stars 26 forks source link

BUG/Requirement: render() test-helper: currently impossible to set services & `this` context for templateOnlyComponents #89

Open izelnakri opened 3 years ago

izelnakri commented 3 years ago

I've done more investigation after my PR: https://github.com/glimmerjs/glimmer-experimental/pull/88 . I found that even my PR doesn't completely solve this problem, it seems like this is a limitation of our current compiler.

If I understood correctly our glimmerx babel plugin/compiler compiles the components with their scope: and services concatenated:

(compiledOutputWithScopesObj, serviceOne, serviceTwo)

This is not possible for a render() test-helper function since essentially we are passing down a glimmer templateOnlyComponent. I would appreciate if we could figure out a way to allow this in the glimmerx package or compiler level, so this context can be set directly in the renderComponent API:

  return renderComponent(hbs`
    <h1>{{this.someProperty}}</h1>
  `, {
    element: document.getElementById('ember-testing'),
    // thisContext or context or owner(which sets a context if thats what it does)
    args: argsContext
    services: servicesContextAssignedToThisContext
  });