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/local_message.js to ES6 module.

Anders Kaseorg32288d245c5a
diff --git a/.eslintrc.json b/.eslintrc.json
index 5c17db6fb3c..c3a1301b2d9 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -165,7 +165,6 @@
"list_util": false,
"ListWidget": false,
"localStorage": false,
- "local_message": false,
"location": false,
"message_edit": false,
"message_events": false,
diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.js
index 99d4e2299c3..7027ab975c9 100644
--- a/frontend_tests/node_tests/compose.js
+++ b/frontend_tests/node_tests/compose.js
@@ -58,7 +58,8 @@ rewiremock("../../static/js/rendered_markdown").with({
update_elements: () => {},
});
-const local_message = set_global("local_message", {});
+const local_message = {__esModule: true};
+rewiremock("../../static/js/local_message").with(local_message);
const transmit = set_global("transmit", {});
const channel = {__esModule: true};
rewiremock("../../static/js/channel").with(channel);
diff --git a/frontend_tests/node_tests/echo.js b/frontend_tests/node_tests/echo.js
index 0b2c608cd1d..94c627189e7 100644
--- a/frontend_tests/node_tests/echo.js
+++ b/frontend_tests/node_tests/echo.js
@@ -8,7 +8,8 @@ const rewiremock = require("rewiremock/node");
const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
-const local_message = set_global("local_message", {});
+const local_message = {__esModule: true};
+rewiremock("../../static/js/local_message").with(local_message);
const markdown = {__esModule: true};
rewiremock("../../static/js/markdown").with(markdown);
const page_params = set_global("page_params", {});
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index 3af19731845..dccd2ba4aa5 100644
--- a/static/js/bundles/app.js
+++ b/static/js/bundles/app.js
@@ -24,7 +24,6 @@ import "../widgetize";
import "../message_list";
import "../narrow";
import "../reload";
-import "../local_message";
import "../sent_messages";
import "../compose_state";
import "../compose_actions";
diff --git a/static/js/echo.js b/static/js/echo.js
index 8b4decb61dd..0375b536ea2 100644
--- a/static/js/echo.js
+++ b/static/js/echo.js
@@ -1,4 +1,5 @@
import * as alert_words from "./alert_words";
+import * as local_message from "./local_message";
import * as markdown from "./markdown";
import * as narrow_state from "./narrow_state";
import * as people from "./people";
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index bc220cbe598..d2969f11b34 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -40,7 +40,6 @@ declare let input_pill: any;
declare let lightbox: any;
declare let list_util: any;
declare let list_widget: any;
-declare let local_message: any;
declare let message_edit: any;
declare let message_events: any;
declare let message_fetch: any;
diff --git a/static/js/local_message.js b/static/js/local_message.js
index cf981be9f2e..28a60085896 100644
--- a/static/js/local_message.js
+++ b/static/js/local_message.js
@@ -1,17 +1,15 @@
-"use strict";
-
function truncate_precision(float) {
return Number.parseFloat(float.toFixed(3));
}
-exports.insert_message = function (message) {
+export function insert_message(message) {
// It is a little bit funny to go through the message_events
// codepath, but it's sort of the idea behind local echo that
// we are simulating server events before they actually arrive.
message_events.insert_new_messages([message], true);
-};
+}
-exports.get_next_id_float = (function () {
+export const get_next_id_float = (function () {
const already_used = new Set();
return function () {
@@ -47,5 +45,3 @@ exports.get_next_id_float = (function () {
return local_id_float;
};
})();
-
-window.local_message = exports;