1
1
import config from 'ember-get-config'
2
+ import Ember from 'ember'
2
3
3
4
let name = config . modulePrefix ;
4
5
@@ -25,16 +26,29 @@ class ApplicationContainer extends HTMLElement {
25
26
let rootParent = document . createElement ( 'div' )
26
27
_appendStyles ( rootParent , this . #styles)
27
28
let rootElement = document . createElement ( 'div' )
29
+ rootElement . setAttribute ( 'data-ember-root-element' , Ember . guidFor ( this ) )
28
30
this . #shadowRoot. appendChild ( rootParent )
29
31
rootParent . appendChild ( rootElement )
30
32
31
- // Actually start the app
33
+ }
34
+
35
+ connectedCallback ( ) {
36
+ if ( this . #application || ! this . isConnected ) {
37
+ return
38
+ }
39
+
32
40
let app = require ( `${ name } /app` ) . default . create ( {
33
- rootElement
41
+ rootElement : this . #shadowRoot . querySelector ( `[data-ember-root-element=" ${ Ember . guidFor ( this ) } "]` )
34
42
} )
35
43
this . #application = app
36
44
}
37
45
46
+ disconnectedCallback ( ) {
47
+ if ( ! this . #application. isDestroyed && ! this . #application. isDestroying ) {
48
+ this . #application. destroy ( )
49
+ }
50
+ }
51
+
38
52
// That makes the application accessible via:
39
53
// document.querySelector('application-name').__EMBER_APPLICATION
40
54
get __EMBER_APPLICATION ( ) {
@@ -53,8 +67,6 @@ customElements.define(componentName, ApplicationContainer)
53
67
/**
54
68
* TODO
55
69
* RECOMMEND to remove export-application-global
56
- * Allow for multiple instances (clean exportApplicationGlobal)
57
- * Destruction of comonent <=> Destruction of the app
58
70
* Attributes and slots
59
71
* More isolation
60
72
*/
0 commit comments