forked from mali3days/jshardtryingoop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
62 lines (56 loc) · 1.49 KB
/
script.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
const register = {};
let id = 0;
class Component {
constructor() {
this.id = id++;
register[this.id] = this;
}
}
const postDate = {
author: "Some Date",
title: "title",
body: "Loren....."
};
const postDate2 = {
author: "Vasya",
title: "title2",
body: "Loren Ipsum....."
};
// function BlogPost(data) {
// return `<div class="post">
// <div class="author">${data.author}</div>
// <div class="title">${data.title}</div>
// <div class="body">${data.body}</div>
// </div>`;
// }
// document.querySelector("body").innerHTML = BlogPost(postDate);
class BlogPost extends Component {
constructor({ author, title, body }) {
super();
this.state = {
author,
title,
body
};
}
render() {
const { author, title, body } = this.state;
return `<div class="post">
<div class="author">${author}</div>
<div class="title">${title}</div>
<textarea class="body-txt" onchange='register[${
this.id
}].updateBody(this.value)'>${body}</textarea>
<div class="id">${"id >" + " " + this.id}</div>
</div>`;
}
updateBody(value) {
this.state.body = value;
console.log(register);
}
}
let post = new BlogPost(postDate);
document.querySelector("body").innerHTML = post.render();
let post2 = new BlogPost(postDate2);
document.querySelector("body").innerHTML += `</br> ${post2.render()}`;
console.log(register);