-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAppFooter.js
More file actions
63 lines (52 loc) · 1.73 KB
/
AppFooter.js
File metadata and controls
63 lines (52 loc) · 1.73 KB
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
/**
* @class AppFooter
* @description Sample footer component.
* @extends HTMLElement
*/
class AppFooter extends HTMLElement {
constructor() {
super();
//
// Grab reference to global (app-level) state manager
//
this.appRoot = document.querySelector('app-root');
this.appState = this.appRoot.state;
// Trigger some specific re-rendering upon global state change
this.appRoot.addEventListener('StateManagerUpdate', this.onAppRootStateUpdate.bind(this));
//
// Local state
//
this.state = new StateManager(this, 'AppFooter', {
screenChangesCount: -1
});
// Note for documentation purposes:
// If we wanted to listen to changes in this StateManager instance, bound to `this`,
// we would do the following:
// this.addEventListener('StateManagerUpdate', this.doSomethingWhenLocalStateChanges.bind(this))
}
connectedCallback() {
this.renderInnerHTML();
}
/**
* Called upon AppRoot's state update.
* Updates the screen changes counter.
* @param {Event} event - Event fired by StateManager
*/
onAppRootStateUpdate(event) {
// If data.navigation.currentScreen was updated, increment clicks counter and re-render.
if( event.detail.updatedProperty === 'currentScreen' && event.detail.updatedPropertyPath === 'data.navigation') {
this.state.data.screenChangesCount = this.state.data.screenChangesCount + 1;
this.renderInnerHTML();
}
}
/**
* Generates and replace inner HTML content
*/
renderInnerHTML() {
let screenChangesCount = this.state.data.screenChangesCount;
this.innerHTML = /*html*/`
<p>You changed screens ${screenChangesCount} times.</p>
`;
}
}
customElements.define('app-footer', AppFooter);