Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Ember/Glimmer interop #58

Merged
merged 1 commit into from
Apr 9, 2020
Merged

[FEATURE] Ember/Glimmer interop #58

merged 1 commit into from
Apr 9, 2020

Conversation

pzuraq
Copy link
Member

@pzuraq pzuraq commented Apr 7, 2020

This PR adds basic Ember/Glimmer interop for GlimmerX. This allows users
to write libraries and components using GlimmerX in both frameworks. It
works by providing alternative implementations for each package, one for
standard Glimmer/TS/Webpack builds, one for Ember builds. Eventually the
goal is to unify these as much as possible, but for now this unlocks
experimentation and cross-compatiblity.

Changes include:

  • Babel plugin has been updated to include an ember option and the
    ability to pass a custom precompileTemplate function, for the Ember
    side to use.
  • Most Glimmer imports have been replaced with no-ops (like on and
    fn). Ember templates and components still rely on resolution, so
    these "just work" anyways.
  • User "imports" will continue to work in Ember, as long as the files
    are exported in the correct place, since Ember still relies on
    resolution and doesn't have true imports.
  • Services work, and an empty base Service class has been added so
    that users can import and extend it, like they would in Ember. In the
    Ember side, services need to be exported from the /services folder
    like normal. In the Glimmer side, they need to be instantiated and
    passed to renderComponent.

The PR also adds smoke tests for the new functionality, to make sure we
don't accidentally break it.

@pzuraq pzuraq force-pushed the ember/glimmer-interop branch 3 times, most recently from 084ef34 to 937446b Compare April 7, 2020 23:29
Comment on lines +4 to +8
const precompileTemplate = (templateString, templateTokens, options) => {
let compiled = templateCompiler.precompile(templateString, options);

return `Ember.HTMLBars.template(${compiled})`;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we leverage ember-cli-htmlbars here? We know the host will already have it...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you mean exactly? Instead of loading the template compiler here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the template compiler loading is "tricky". The current implementation will not support the app having AST tranforms (e.g. for {{t/{{t-def, et al) because it doesn't load plugins.

This is fine for now, but I'd like to add an API to ember-cli-htmlbars that we can just use directly.

packages/@glimmerx/component/index.ts Show resolved Hide resolved
packages/@glimmerx/service/package.json Outdated Show resolved Hide resolved
@pzuraq pzuraq force-pushed the ember/glimmer-interop branch 2 times, most recently from 51b6d85 to 6305589 Compare April 9, 2020 15:48
Copy link
Collaborator

@chiragpat chiragpat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM. Super happy we can finally have some form of interop between glimmerjs and ember

@@ -1 +1,3 @@
export { service } from './src/decorator';

export default class Service {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the plan to add more things here? or is this class needed to match the default export from @ember/service?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class is just needed to match the default export for the time being. We can consider adding more in the future, but for now an empty class is probably fine, don't want to commit to more API space before we think it through.

@pzuraq pzuraq force-pushed the ember/glimmer-interop branch from 6305589 to fddad85 Compare April 9, 2020 17:55
This PR adds basic Ember/Glimmer interop for GlimmerX. This allows users
to write libraries and components using GlimmerX in both frameworks. It
works by providing alternative implementations for each package, one for
standard Glimmer/TS/Webpack builds, one for Ember builds. Eventually the
goal is to unify these as much as possible, but for now this unlocks
experimentation and cross-compatiblity.

Changes include:

- Babel plugin has been updated to include an `ember` option and the
  ability to pass a custom `precompileTemplate` function, for the Ember
  side to use.
- Most Glimmer imports have been replaced with no-ops (like `on` and
  `fn`). Ember templates and components still rely on resolution, so
  these "just work" anyways.
- User "imports" will continue to work in Ember, as long as the files
  are exported in the correct place, since Ember still relies on
  resolution and doesn't have true imports.
- Services work, and an empty base `Service` class has been added so
  that users can import and extend it, like they would in Ember. In the
  Ember side, services need to be exported from the `/services` folder
  like normal. In the Glimmer side, they need to be instantiated and
  passed to `renderComponent`.

The PR also adds smoke tests for the new functionality, to make sure we
don't accidentally break it.
@pzuraq pzuraq force-pushed the ember/glimmer-interop branch from fddad85 to 62e46f0 Compare April 9, 2020 18:29
@pzuraq pzuraq merged commit 2cb830b into master Apr 9, 2020
@pzuraq pzuraq deleted the ember/glimmer-interop branch April 9, 2020 18:37
@pzuraq pzuraq added the enhancement New feature or request label Apr 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants