MCPcopy Index your code
hub / github.com/marijnh/Eloquent-JavaScript / constructor

Method constructor

code/solutions/21_2_comment_field_resets.mjs:5–30  ·  view source on GitHub ↗
(talk, dispatch)

Source from the content-addressed store, hash-verified

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;

Callers

nothing calls this directly

Calls 2

syncStateMethod · 0.95
eltFunction · 0.85

Tested by

no test coverage detected