-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMMM-Template.js
64 lines (55 loc) · 1.64 KB
/
MMM-Template.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
Module.register("MMM-Template", {
defaults: {
exampleContent: ""
},
/**
* Apply the default styles.
*/
getStyles() {
return ["template.css"]
},
/**
* Pseudo-constructor for our module. Initialize stuff here.
*/
start() {
this.templateContent = this.config.exampleContent
// set timeout for next random text
setInterval(() => this.addRandomText(), 3000)
},
/**
* Handle notifications received by the node helper.
* So we can communicate between the node helper and the module.
*
* @param {string} notification - The notification identifier.
* @param {any} payload - The payload data`returned by the node helper.
*/
socketNotificationReceived: function (notification, payload) {
if (notification === "EXAMPLE_NOTIFICATION") {
this.templateContent = `${this.config.exampleContent} ${payload.text}`
this.updateDom()
}
},
/**
* Render the page we're on.
*/
getDom() {
const wrapper = document.createElement("div")
wrapper.innerHTML = `<b>Title</b><br />${this.templateContent}`
return wrapper
},
addRandomText() {
this.sendSocketNotification("GET_RANDOM_TEXT", { amountCharacters: 15 })
},
/**
* This is the place to receive notifications from other modules or the system.
*
* @param {string} notification The notification ID, it is preferred that it prefixes your module name
* @param {number} payload the payload type.
*/
notificationReceived(notification, payload) {
if (notification === "TEMPLATE_RANDOM_TEXT") {
this.templateContent = `${this.config.exampleContent} ${payload}`
this.updateDom()
}
}
})