Skip to content

Commit 4774912

Browse files
committed
Fixes integrations in apps, handles custom Element lifecycle events
1 parent fb7fa34 commit 4774912

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

addon/create-web-components.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import config from 'ember-get-config'
2+
import Ember from 'ember'
23

34
let name = config.modulePrefix;
45

@@ -25,16 +26,29 @@ class ApplicationContainer extends HTMLElement {
2526
let rootParent = document.createElement('div')
2627
_appendStyles(rootParent, this.#styles)
2728
let rootElement = document.createElement('div')
29+
rootElement.setAttribute('data-ember-root-element', Ember.guidFor(this))
2830
this.#shadowRoot.appendChild(rootParent)
2931
rootParent.appendChild(rootElement)
3032

31-
// Actually start the app
33+
}
34+
35+
connectedCallback() {
36+
if (this.#application || !this.isConnected) {
37+
return
38+
}
39+
3240
let app = require(`${name}/app`).default.create({
33-
rootElement
41+
rootElement: this.#shadowRoot.querySelector(`[data-ember-root-element="${Ember.guidFor(this)}"]`)
3442
})
3543
this.#application = app
3644
}
3745

46+
disconnectedCallback() {
47+
if (!this.#application.isDestroyed && !this.#application.isDestroying) {
48+
this.#application.destroy()
49+
}
50+
}
51+
3852
// That makes the application accessible via:
3953
// document.querySelector('application-name').__EMBER_APPLICATION
4054
get __EMBER_APPLICATION() {
@@ -53,8 +67,6 @@ customElements.define(componentName, ApplicationContainer)
5367
/**
5468
* TODO
5569
* RECOMMEND to remove export-application-global
56-
* Allow for multiple instances (clean exportApplicationGlobal)
57-
* Destruction of comonent <=> Destruction of the app
5870
* Attributes and slots
5971
* More isolation
6072
*/

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"test:all": "ember try:each"
2222
},
2323
"dependencies": {
24-
"ember-cli-babel": "^7.7.3"
24+
"ember-cli-babel": "^7.7.3",
25+
"ember-get-config": "^0.2.4"
2526
},
2627
"devDependencies": {
2728
"@ember/optional-features": "^0.7.0",
@@ -36,7 +37,6 @@
3637
"ember-cli-template-lint": "^1.0.0-beta.1",
3738
"ember-cli-uglify": "^2.1.0",
3839
"ember-disable-prototype-extensions": "^1.1.3",
39-
"ember-get-config": "^0.2.4",
4040
"ember-load-initializers": "^2.0.0",
4141
"ember-maybe-import-regenerator": "^0.1.6",
4242
"ember-qunit": "^4.4.1",

0 commit comments

Comments
 (0)