poll_data: Move `handler` class property inside the constructor.

Declares the `handler` property inside the class constructor and not
after the constructor to avoid eslint and typescript errors when we
convert this module to typescript.
This commit is contained in:
Lalit 2023-06-02 12:30:29 +05:30 committed by Tim Abbott
parent b80a205dbe
commit 3fb27c9b1c
1 changed files with 134 additions and 134 deletions

View File

@ -28,64 +28,7 @@ export class PollData {
this.comma_separated_names = comma_separated_names;
this.report_error_function = report_error_function;
if (question) {
this.set_question(question);
}
for (const [i, option] of options.entries()) {
this.handle.new_option.inbound("canned", {
idx: i,
option,
});
}
}
set_question(new_question) {
this.input_mode = false;
this.poll_question = new_question;
}
get_question() {
return this.poll_question;
}
set_input_mode() {
this.input_mode = true;
}
clear_input_mode() {
this.input_mode = false;
}
get_input_mode() {
return this.input_mode;
}
get_widget_data() {
const options = [];
for (const [key, obj] of this.key_to_option) {
const voters = [...obj.votes.keys()];
const current_user_vote = voters.includes(this.me);
options.push({
option: obj.option,
names: this.comma_separated_names(voters),
count: voters.length,
key,
current_user_vote,
});
}
const widget_data = {
options,
question: this.poll_question,
};
return widget_data;
}
handle = {
this.handle = {
new_option: {
outbound: (option) => {
const event = {
@ -219,6 +162,63 @@ export class PollData {
},
};
if (question) {
this.set_question(question);
}
for (const [i, option] of options.entries()) {
this.handle.new_option.inbound("canned", {
idx: i,
option,
});
}
}
set_question(new_question) {
this.input_mode = false;
this.poll_question = new_question;
}
get_question() {
return this.poll_question;
}
set_input_mode() {
this.input_mode = true;
}
clear_input_mode() {
this.input_mode = false;
}
get_input_mode() {
return this.input_mode;
}
get_widget_data() {
const options = [];
for (const [key, obj] of this.key_to_option) {
const voters = [...obj.votes.keys()];
const current_user_vote = voters.includes(this.me);
options.push({
option: obj.option,
names: this.comma_separated_names(voters),
count: voters.length,
key,
current_user_vote,
});
}
const widget_data = {
options,
question: this.poll_question,
};
return widget_data;
}
handle_event(sender_id, data) {
const type = data.type;
if (this.handle[type] && this.handle[type].inbound) {