-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathember-islands.js
52 lines (40 loc) · 1.07 KB
/
ember-islands.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import Ember from 'ember';
import Reconciler from 'ember-islands/utils/reconciler';
import queryIslandComponents from 'ember-islands/utils/query-island-components';
import getRenderComponent from 'ember-islands/utils/get-render-component';
let eiInstance;
export default Ember.Component.extend({
tagName: '',
init() {
this._super(...arguments);
let renderComponent = getRenderComponent(this);
this.reconciler = new Reconciler({
initialRender(c) {
return renderComponent(c);
},
update(c) {
delete c.attrs.innerContent;
c.instance.setProperties(c.attrs);
},
destroy(c) {
c.destroy();
}
});
eiInstance = this;
},
reconcile() {
this.reconciler.reconcileAgainst(queryIslandComponents());
},
getRenderedComponents() {
return this.reconciler.renderedComponentsAsArray();
},
didInsertElement() {
this.reconcile();
},
willDestroyElement() {
this.reconciler.forEachRenderedComponent(c => c.destroy());
}
});
export function getInstance() {
return eiInstance;
}