-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathliquid-wormhole.js
59 lines (44 loc) · 1.53 KB
/
liquid-wormhole.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
53
54
55
56
57
58
59
import Component from '@ember/component';
import { typeOf } from '@ember/utils';
import { inject as service } from '@ember/service';
import { computed } from '@ember/object';
import { reads } from '@ember/object/computed';
import { guidFor } from '@ember/object/internals';
import layout from '../templates/components/liquid-wormhole';
export default Component.extend({
layout,
to: reads('destination'),
liquidWormholeService: service('liquid-wormhole'),
stack: computed(function() {
return guidFor(this);
}),
// Truthy value by default
value: true,
init() {
const wormholeClass = this.get('class');
const wormholeId = this.get('stack') || this.get('id');
this.set('wormholeClass', wormholeClass);
this.set('wormholeId', wormholeId);
if (typeOf(this.get('send')) !== 'function') {
this.set('hasSend', true);
}
this._super(...arguments);
},
didUpdateAttrs() {
this._super(...arguments);
this.get('liquidWormholeService').removeWormhole(this, this.get('to'));
this.get('liquidWormholeService').appendWormhole(this, this.get('to'));
},
didInsertElement() {
const nodes = this.$().children();
this.set('nodes', nodes);
this.element.className = 'liquid-wormhole-container';
this.element.id = '';
this.get('liquidWormholeService').appendWormhole(this, this.get('to'));
this._super.apply(this, arguments);
},
willDestroyElement() {
this.get('liquidWormholeService').removeWormhole(this, this.get('to'));
this._super.apply(this, arguments);
}
});