-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.js
65 lines (47 loc) · 1.25 KB
/
view.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
60
61
62
63
64
65
import { Component, define, event } from '@xinix/xin';
export class View extends Component {
get props () {
return {
...super.props,
parameters: {
type: Object,
},
};
}
ready () {
super.ready();
this.setAttribute('xin-view', '');
}
async attached () {
super.attached();
this.routers = [...this.querySelectorAll('xin-router')];
await Promise.all(this.routers.map(async router => {
await event(router).waitFor('router-attach');
}));
this.fire('view-attach');
}
async __viewEnter (route, ctx) {
this.set('ctx', ctx);
this.set('parameters', ctx.parameters);
await this.focusing();
event(this).fire('focusing');
if (this.parentElement !== route.parentElement) {
await route.parentElement.insertBefore(this, route);
await event(this).waitFor('view-attach');
}
await Promise.all(this.routers.map(async router => {
await router.__routerDispatch(ctx);
}));
await this.focused();
event(this).fire('focus');
}
async __viewLeave (route) {
await route.parentElement.removeChild(this);
await this.blurred();
event(this).fire('blur');
}
focusing () {}
focused () {}
blurred () {}
}
define('xin-view', View);