From e05293a257987f255af6aa727e2794ee736232a2 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sat, 27 Feb 2021 15:48:19 -0800 Subject: [PATCH] js: Convert static/js/reload_state.js to ES6 module. Signed-off-by: Anders Kaseorg --- .eslintrc.json | 1 - frontend_tests/node_tests/channel.js | 1 - frontend_tests/node_tests/compose_actions.js | 2 +- frontend_tests/node_tests/people_errors.js | 13 ++++++++++--- frontend_tests/node_tests/presence.js | 11 +++++++++-- frontend_tests/node_tests/server_events.js | 2 +- frontend_tests/node_tests/transmit.js | 3 ++- static/js/bundles/app.js | 1 - static/js/channel.js | 2 ++ static/js/compose_actions.js | 1 + static/js/global.d.ts | 1 - static/js/people.js | 1 + static/js/presence.js | 1 + static/js/reload.js | 1 + static/js/reload_state.js | 20 ++++++++------------ static/js/server_events.js | 1 + static/js/transmit.js | 1 + 17 files changed, 39 insertions(+), 24 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 196704475c..68b11e8f33 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -194,7 +194,6 @@ "realm_night_logo": false, "recent_topics": false, "reload": false, - "reload_state": false, "reminder": false, "resize": false, "scroll_bar": false, diff --git a/frontend_tests/node_tests/channel.js b/frontend_tests/node_tests/channel.js index 0cc76448c4..247add709d 100644 --- a/frontend_tests/node_tests/channel.js +++ b/frontend_tests/node_tests/channel.js @@ -14,7 +14,6 @@ set_global("setTimeout", (f, delay) => { f(); }); -zrequire("reload_state"); const channel = zrequire("channel"); const default_stub_xhr = "default-stub-xhr"; diff --git a/frontend_tests/node_tests/compose_actions.js b/frontend_tests/node_tests/compose_actions.js index 0cf3dcb74e..7df91fc9c0 100644 --- a/frontend_tests/node_tests/compose_actions.js +++ b/frontend_tests/node_tests/compose_actions.js @@ -23,7 +23,7 @@ rewiremock("../../static/js/compose_pm_pill").with(compose_pm_pill); const hash_util = set_global("hash_util", {}); -set_global("reload_state", { +rewiremock("../../static/js/reload_state").with({ is_in_progress: () => false, }); diff --git a/frontend_tests/node_tests/people_errors.js b/frontend_tests/node_tests/people_errors.js index 20b696b69b..5e8c5e7cb2 100644 --- a/frontend_tests/node_tests/people_errors.js +++ b/frontend_tests/node_tests/people_errors.js @@ -2,12 +2,18 @@ const {strict: assert} = require("assert"); -const {set_global, zrequire} = require("../zjsunit/namespace"); +const rewiremock = require("rewiremock/node"); + +const {zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const reload_state = set_global("reload_state", { +const reload_state = { + __esModule: true, is_in_progress: () => false, -}); +}; + +rewiremock("../../static/js/reload_state").with(reload_state); +rewiremock.enable(); const people = zrequire("people"); @@ -115,3 +121,4 @@ run_test("blueslip", () => { blueslip.expect("error", "Trying to set undefined field id"); people.set_custom_profile_field_data(maria.user_id, {}); }); +rewiremock.disable(); diff --git a/frontend_tests/node_tests/presence.js b/frontend_tests/node_tests/presence.js index 928a6442d8..db7a21c368 100644 --- a/frontend_tests/node_tests/presence.js +++ b/frontend_tests/node_tests/presence.js @@ -2,13 +2,19 @@ const {strict: assert} = require("assert"); +const rewiremock = require("rewiremock/node"); + const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const server_events = set_global("server_events", {}); -const reload_state = set_global("reload_state", { +const reload_state = { + __esModule: true, is_in_progress: () => false, -}); +}; + +rewiremock("../../static/js/reload_state").with(reload_state); +rewiremock.enable(); const people = zrequire("people"); const presence = zrequire("presence"); @@ -326,3 +332,4 @@ run_test("update_info_from_event", () => { last_active: 1000, }); }); +rewiremock.disable(); diff --git a/frontend_tests/node_tests/server_events.js b/frontend_tests/node_tests/server_events.js index a4669b9506..67fbad372b 100644 --- a/frontend_tests/node_tests/server_events.js +++ b/frontend_tests/node_tests/server_events.js @@ -28,7 +28,7 @@ set_global("home_msg_list", { }, }); set_global("page_params", {test_suite: false}); -set_global("reload_state", { +rewiremock("../../static/js/reload_state").with({ is_in_progress() { return false; }, diff --git a/frontend_tests/node_tests/transmit.js b/frontend_tests/node_tests/transmit.js index fb2aedf764..fd86927de1 100644 --- a/frontend_tests/node_tests/transmit.js +++ b/frontend_tests/node_tests/transmit.js @@ -13,7 +13,8 @@ const page_params = set_global("page_params", {}); const channel = {__esModule: true}; rewiremock("../../static/js/channel").with(channel); const reload = set_global("reload", {}); -const reload_state = set_global("reload_state", {}); +const reload_state = {__esModule: true}; +rewiremock("../../static/js/reload_state").with(reload_state); const sent_messages = set_global("sent_messages", { start_tracking_message: noop, report_server_ack: noop, diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js index cac35e6ade..8d4bd3e4ac 100644 --- a/static/js/bundles/app.js +++ b/static/js/bundles/app.js @@ -23,7 +23,6 @@ import "../stream_list"; import "../widgetize"; import "../message_list"; import "../narrow"; -import "../reload_state"; import "../reload"; import "../compose_fade"; import "../markdown"; diff --git a/static/js/channel.js b/static/js/channel.js index 0e9e64889e..616998c0c5 100644 --- a/static/js/channel.js +++ b/static/js/channel.js @@ -1,3 +1,5 @@ +import * as reload_state from "./reload_state"; + const pending_requests = []; function add_pending_request(jqXHR) { diff --git a/static/js/compose_actions.js b/static/js/compose_actions.js index 5909f95489..609598790b 100644 --- a/static/js/compose_actions.js +++ b/static/js/compose_actions.js @@ -11,6 +11,7 @@ const drafts = require("./drafts"); const message_viewport = require("./message_viewport"); const narrow_state = require("./narrow_state"); const people = require("./people"); +const reload_state = require("./reload_state"); exports.blur_compose_inputs = function () { $(".message_comp").find("input, textarea, button, #private_message_recipient").trigger("blur"); diff --git a/static/js/global.d.ts b/static/js/global.d.ts index 94dcc68b68..f7994f54d3 100644 --- a/static/js/global.d.ts +++ b/static/js/global.d.ts @@ -67,7 +67,6 @@ declare let realm_icon: any; declare let realm_logo: any; declare let recent_topics: any; declare let reload: any; -declare let reload_state: any; declare let reminder: any; declare let resize: any; declare let scroll_bar: any; diff --git a/static/js/people.js b/static/js/people.js index 2b825bf35f..31e4f9d2ff 100644 --- a/static/js/people.js +++ b/static/js/people.js @@ -5,6 +5,7 @@ import _ from "lodash"; import * as typeahead from "../shared/js/typeahead"; import {FoldDict} from "./fold_dict"; +import * as reload_state from "./reload_state"; import * as settings_data from "./settings_data"; import * as util from "./util"; diff --git a/static/js/presence.js b/static/js/presence.js index 65e7110f93..ebb129f1ed 100644 --- a/static/js/presence.js +++ b/static/js/presence.js @@ -1,6 +1,7 @@ "use strict"; const people = require("./people"); +const reload_state = require("./reload_state"); // This module just manages data. See activity.js for // the UI of our buddy list. diff --git a/static/js/reload.js b/static/js/reload.js index af35a5e3b1..03ddf072dc 100644 --- a/static/js/reload.js +++ b/static/js/reload.js @@ -2,6 +2,7 @@ const {localstorage} = require("./localstorage"); const narrow_state = require("./narrow_state"); +const reload_state = require("./reload_state"); const util = require("./util"); // Read https://zulip.readthedocs.io/en/latest/subsystems/hashchange-system.html diff --git a/static/js/reload_state.js b/static/js/reload_state.js index 3e78804402..cfff3fc7d7 100644 --- a/static/js/reload_state.js +++ b/static/js/reload_state.js @@ -1,5 +1,3 @@ -"use strict"; - /* We want his module to load pretty early in the process of starting the app, so that people.js can load early. @@ -12,23 +10,21 @@ let reload_in_progress = false; let reload_pending = false; -exports.is_pending = function () { +export function is_pending() { return reload_pending; -}; +} -exports.is_in_progress = function () { +export function is_in_progress() { return reload_in_progress; -}; +} -exports.set_state_to_pending = function () { +export function set_state_to_pending() { // Why do we never set this back to false? // Because the reload is gonna happen next. :) // I was briefly confused by this, hence the comment. reload_pending = true; -}; +} -exports.set_state_to_in_progress = function () { +export function set_state_to_in_progress() { reload_in_progress = true; -}; - -window.reload_state = exports; +} diff --git a/static/js/server_events.js b/static/js/server_events.js index b125e44052..da8146d0e1 100644 --- a/static/js/server_events.js +++ b/static/js/server_events.js @@ -4,6 +4,7 @@ const _ = require("lodash"); const channel = require("./channel"); const echo = require("./echo"); +const reload_state = require("./reload_state"); const server_events_dispatch = require("./server_events_dispatch"); // Docs: https://zulip.readthedocs.io/en/latest/subsystems/events-system.html diff --git a/static/js/transmit.js b/static/js/transmit.js index 1f553d492a..fefe91a26c 100644 --- a/static/js/transmit.js +++ b/static/js/transmit.js @@ -2,6 +2,7 @@ const channel = require("./channel"); const people = require("./people"); +const reload_state = require("./reload_state"); exports.send_message = function (request, on_success, error) { channel.post({