-
Notifications
You must be signed in to change notification settings - Fork 3
/
SlackAttachment.js
47 lines (38 loc) · 992 Bytes
/
SlackAttachment.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
const { Map } = require("immutable");
const SlackComponent = require("../reconciler/SlackComponent");
module.exports = class SlackAttachment extends SlackComponent {
/**
* @param {SlackRoot} root
* @param {Object} props
*/
constructor(root, props) {
super();
this.root = root;
this.props = props;
this.attachment = new Map();
}
renderProps() {
const { color, timestamp } = this.props;
if (color) {
this.attachment = this.attachment.set("color", color);
}
if (timestamp) {
this.attachment = this.attachment.set("ts", timestamp);
}
}
renderChildren() {
this.children.forEach(child => {
if (child instanceof SlackComponent) {
child.render();
}
});
}
render() {
this.renderProps();
this.renderChildren();
const attachment = this.attachment;
this.root.message = this.root.message.update("attachments", attachments =>
attachments.push(attachment)
);
}
};