Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

js: Convert static/js/poll_widget.js to ES6 module.

Anders Kaseorg472f3bc47826
diff --git a/.eslintrc.json b/.eslintrc.json
index 942f0a48612..c62fdb7d278 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -249,7 +249,6 @@
"upload": false,
"upload_widget": false,
"user_events": false,
- "poll_widget": false,
"widgetize": false,
"zxcvbn": false
}
diff --git a/frontend_tests/node_tests/widgetize.js b/frontend_tests/node_tests/widgetize.js
index e5ce37d9ca0..6b26ba0e9c4 100644
--- a/frontend_tests/node_tests/widgetize.js
+++ b/frontend_tests/node_tests/widgetize.js
@@ -2,16 +2,21 @@
const {strict: assert} = require("assert");
+const rewiremock = require("rewiremock/node");
+
const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
-const poll_widget = set_global("poll_widget", {});
+const poll_widget = {__esModule: true};
+rewiremock("../../static/js/poll_widget").with(poll_widget);
set_global("document", "document-stub");
const narrow_state = set_global("narrow_state", {});
set_global("current_msg_list", {});
+rewiremock.enable();
+
const widgetize = zrequire("widgetize");
run_test("activate", (override) => {
@@ -176,3 +181,4 @@ run_test("activate", (override) => {
});
widgetize.set_widgets_for_list();
});
+rewiremock.disable();
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index 4efebb00c6f..29aa19067a8 100644
--- a/static/js/bundles/app.js
+++ b/static/js/bundles/app.js
@@ -20,7 +20,6 @@ import "../setup";
import "../unread_ops";
import "../unread";
import "../stream_list";
-import "../poll_widget";
import "../widgetize";
import "../submessage";
import "../message_list_view";
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index 7de12ec674c..7757e1a7a6e 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -63,7 +63,6 @@ declare let padded_widget: any;
declare let page_params: any;
declare let panels: any;
declare let pointer: any;
-declare let poll_widget: any;
declare let popovers: any;
declare let presence: any;
declare let reactions: any;
diff --git a/static/js/poll_widget.js b/static/js/poll_widget.js
index 0dfe1ede953..7434f26ec43 100644
--- a/static/js/poll_widget.js
+++ b/static/js/poll_widget.js
@@ -1,11 +1,9 @@
-"use strict";
+import render_widgets_poll_widget from "../templates/widgets/poll_widget.hbs";
+import render_widgets_poll_widget_results from "../templates/widgets/poll_widget_results.hbs";
-const render_widgets_poll_widget = require("../templates/widgets/poll_widget.hbs");
-const render_widgets_poll_widget_results = require("../templates/widgets/poll_widget_results.hbs");
+import * as people from "./people";
-const people = require("./people");
-
-class PollData {
+export class PollData {
// This object just holds data for a poll, although it
// works closely with the widget's concept of how data
// should be represented for rendering, plus how the
@@ -177,9 +175,8 @@ class PollData {
return data.some((el) => el.option === latest_option);
}
}
-exports.PollData = PollData;
-exports.activate = function (opts) {
+export function activate(opts) {
const elem = opts.elem;
const callback = opts.callback;
@@ -368,6 +365,4 @@ exports.activate = function (opts) {
build_widget();
render_question();
render_results();
-};
-
-window.poll_widget = exports;
+}
diff --git a/static/js/widgetize.js b/static/js/widgetize.js
index 6682a205dd7..054d2603a4f 100644
--- a/static/js/widgetize.js
+++ b/static/js/widgetize.js
@@ -1,5 +1,6 @@
"use strict";
+const poll_widget = require("./poll_widget");
const todo_widget = require("./todo_widget");
const zform = require("./zform");