-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Chris Garrett
committed
Apr 7, 2020
1 parent
e333dba
commit 084ef34
Showing
45 changed files
with
359 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export { default } from '@glimmer/component'; | ||
export { tracked } from '@glimmer/tracking'; | ||
|
||
export function hbs() { | ||
throw new Error('hbs template should have been compiled at build time'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
function makePrecompileTemplate(templateCompiler) { | ||
const precompileTemplate = (templateString, templateTokens, options) => { | ||
let compiled = templateCompiler.precompile(templateString, options); | ||
|
||
return `Ember.HTMLBars.template(${compiled})`; | ||
}; | ||
|
||
precompileTemplate.baseDir = () => __dirname; | ||
|
||
return precompileTemplate; | ||
} | ||
|
||
module.exports = { | ||
name: require('./package').name, | ||
|
||
included(parent) { | ||
this._super.included.apply(this, arguments); | ||
|
||
let { hasPlugin, addPlugin } = require('ember-cli-babel-plugin-helpers'); | ||
|
||
if (!hasPlugin(parent, '@glimmerx/babel-plugin-component-templates')) { | ||
const ember = this.project.findAddonByName('ember-source'); | ||
const templateCompiler = require(ember.absolutePaths.templateCompiler); | ||
|
||
addPlugin(parent, [ | ||
require.resolve('@glimmerx/babel-plugin-component-templates'), | ||
{ | ||
ember: true, | ||
|
||
precompileTemplate: makePrecompileTemplate(templateCompiler), | ||
}, | ||
]); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
export { default } from '@glimmer/component'; | ||
export { tracked } from '@glimmer/tracking'; | ||
export { hbs } from './src/hbs'; | ||
|
||
export function hbs(_strings: TemplateStringsArray) { | ||
throw new Error('hbs template should have been compiled at build time'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function helper() { | ||
throw new Error('helper() has not been implemented in Ember yet.'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export { helper, Helper } from './-private/helper'; | ||
|
||
export function fn() { | ||
throw new Error( | ||
'Attempted to call {{fn}} directly. {{fn}} is built in in Ember, so it should automatically resolve. This function is for interop with Glimmer.js only.' | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
name: require('./package').name, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export { action } from '@ember/object'; | ||
|
||
export function on() { | ||
throw new Error( | ||
'Attempted to call {{on}} directly. {{on}} is built in in Ember, so it should automatically resolve. This function is for interop with Glimmer.js only.' | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
name: require('./package').name, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default, inject as service } from '@ember/service'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
name: require('./package').name, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export { service } from './src/decorator'; | ||
|
||
export default class Service {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.