MCPcopy Create free account
hub / github.com/marijnh/Eloquent-JavaScript / Talk

Class Talk

code/solutions/21_2_comment_field_resets.mjs:4–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2// component from skillsharing/public/skillsharing_client.js
3
4class Talk {
5 constructor(talk, dispatch) {
6 this.comments = elt("div");
7 this.dom = elt(
8 "section", {className: "talk"},
9 elt("h2", null, talk.title, " ", elt("button", {
10 type: "button",
11 onclick: () => dispatch({type: "deleteTalk",
12 talk: talk.title})
13 }, "Delete")),
14 elt("div", null, "by ",
15 elt("strong", null, talk.presenter)),
16 elt("p", null, talk.summary),
17 this.comments,
18 elt("form", {
19 onsubmit(event) {
20 event.preventDefault();
21 let form = event.target;
22 dispatch({type: "newComment",
23 talk: talk.title,
24 message: form.elements.comment.value});
25 form.reset();
26 }
27 }, elt("input", {type: "text", name: "comment"}), " ",
28 elt("button", {type: "submit"}, "Add comment")));
29 this.syncState(talk);
30 }
31
32 syncState(talk) {
33 this.talk = talk;
34 this.comments.textContent = "";
35 for (let comment of talk.comments) {
36 this.comments.appendChild(renderComment(comment));
37 }
38 }
39}
40
41class SkillShareApp {
42 constructor(state, dispatch) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected