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

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-02-27 15:48:40 -08:00 committed by Tim Abbott
parent e05293a257
commit 527b6a36b3
13 changed files with 26 additions and 18 deletions

View File

@ -193,7 +193,6 @@
"realm_logo": false, "realm_logo": false,
"realm_night_logo": false, "realm_night_logo": false,
"recent_topics": false, "recent_topics": false,
"reload": false,
"reminder": false, "reminder": false,
"resize": false, "resize": false,
"scroll_bar": false, "scroll_bar": false,

View File

@ -3,17 +3,22 @@
const {strict: assert} = require("assert"); const {strict: assert} = require("assert");
const _ = require("lodash"); const _ = require("lodash");
const rewiremock = require("rewiremock/node");
const {set_global, zrequire} = require("../zjsunit/namespace"); const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const reload = set_global("reload", {}); const reload = {__esModule: true};
rewiremock("../../static/js/reload").with(reload);
set_global("setTimeout", (f, delay) => { set_global("setTimeout", (f, delay) => {
assert.equal(delay, 0); assert.equal(delay, 0);
f(); f();
}); });
rewiremock.enable();
const channel = zrequire("channel"); const channel = zrequire("channel");
const default_stub_xhr = "default-stub-xhr"; const default_stub_xhr = "default-stub-xhr";
@ -310,3 +315,4 @@ run_test("xhr_error_message", () => {
msg = "some message"; msg = "some message";
assert.equal(channel.xhr_error_message(msg, xhr), "some message: file not found"); assert.equal(channel.xhr_error_message(msg, xhr), "some message: file not found");
}); });
rewiremock.disable();

View File

@ -41,7 +41,8 @@ const notifications = set_global("notifications", {});
const reactions = set_global("reactions", {}); const reactions = set_global("reactions", {});
const realm_icon = set_global("realm_icon", {}); const realm_icon = set_global("realm_icon", {});
const realm_logo = set_global("realm_logo", {}); const realm_logo = set_global("realm_logo", {});
const reload = set_global("reload", {}); const reload = {__esModule: true};
rewiremock("../../static/js/reload").with(reload);
const scroll_bar = set_global("scroll_bar", {}); const scroll_bar = set_global("scroll_bar", {});
const settings_account = set_global("settings_account", {}); const settings_account = set_global("settings_account", {});
const settings_bots = set_global("settings_bots", {}); const settings_bots = set_global("settings_bots", {});

View File

@ -12,7 +12,8 @@ const noop = () => {};
const page_params = set_global("page_params", {}); const page_params = set_global("page_params", {});
const channel = {__esModule: true}; const channel = {__esModule: true};
rewiremock("../../static/js/channel").with(channel); rewiremock("../../static/js/channel").with(channel);
const reload = set_global("reload", {}); const reload = {__esModule: true};
rewiremock("../../static/js/reload").with(reload);
const reload_state = {__esModule: true}; const reload_state = {__esModule: true};
rewiremock("../../static/js/reload_state").with(reload_state); rewiremock("../../static/js/reload_state").with(reload_state);
const sent_messages = set_global("sent_messages", { const sent_messages = set_global("sent_messages", {

View File

@ -83,7 +83,7 @@ const message_viewport = {
rewiremock("../../static/js/message_viewport").with(message_viewport); rewiremock("../../static/js/message_viewport").with(message_viewport);
set_global("panels", {initialize() {}}); set_global("panels", {initialize() {}});
set_global("popovers", {initialize() {}}); set_global("popovers", {initialize() {}});
set_global("reload", {initialize() {}}); rewiremock("../../static/js/reload").with({initialize() {}});
set_global("scroll_bar", {initialize() {}}); set_global("scroll_bar", {initialize() {}});
const server_events = set_global("server_events", {initialize() {}}); const server_events = set_global("server_events", {initialize() {}});
set_global("settings_sections", {initialize() {}}); set_global("settings_sections", {initialize() {}});

View File

@ -1,3 +1,4 @@
import * as reload from "./reload";
import * as reload_state from "./reload_state"; import * as reload_state from "./reload_state";
const pending_requests = []; const pending_requests = [];

View File

@ -66,7 +66,6 @@ declare let reactions: any;
declare let realm_icon: any; declare let realm_icon: any;
declare let realm_logo: any; declare let realm_logo: any;
declare let recent_topics: any; declare let recent_topics: any;
declare let reload: any;
declare let reminder: any; declare let reminder: any;
declare let resize: any; declare let resize: any;
declare let scroll_bar: any; declare let scroll_bar: any;

View File

@ -1,9 +1,7 @@
"use strict"; import {localstorage} from "./localstorage";
import * as narrow_state from "./narrow_state";
const {localstorage} = require("./localstorage"); import * as reload_state from "./reload_state";
const narrow_state = require("./narrow_state"); import * as util from "./util";
const reload_state = require("./reload_state");
const util = require("./util");
// Read https://zulip.readthedocs.io/en/latest/subsystems/hashchange-system.html // Read https://zulip.readthedocs.io/en/latest/subsystems/hashchange-system.html
function preserve_state(send_after_reload, save_pointer, save_narrow, save_compose) { function preserve_state(send_after_reload, save_pointer, save_narrow, save_compose) {
@ -95,7 +93,7 @@ function preserve_state(send_after_reload, save_pointer, save_narrow, save_compo
// Check if we're doing a compose-preserving reload. This must be // Check if we're doing a compose-preserving reload. This must be
// done before the first call to get_events // done before the first call to get_events
exports.initialize = function () { export function initialize() {
const location = window.location.toString(); const location = window.location.toString();
const hash_fragment = location.slice(location.indexOf("#") + 1); const hash_fragment = location.slice(location.indexOf("#") + 1);
@ -173,7 +171,7 @@ exports.initialize = function () {
activity.set_new_user_input(false); activity.set_new_user_input(false);
hashchange.changehash(vars.oldhash); hashchange.changehash(vars.oldhash);
}; }
function do_reload_app(send_after_reload, save_pointer, save_narrow, save_compose, message) { function do_reload_app(send_after_reload, save_pointer, save_narrow, save_compose, message) {
if (reload_state.is_in_progress()) { if (reload_state.is_in_progress()) {
@ -223,7 +221,7 @@ function do_reload_app(send_after_reload, save_pointer, save_narrow, save_compos
window.location.reload(true); window.location.reload(true);
} }
exports.initiate = function (options) { export function initiate(options) {
options = { options = {
immediate: false, immediate: false,
save_pointer: true, save_pointer: true,
@ -324,7 +322,7 @@ exports.initiate = function (options) {
idle_control = $(document).idle({idle: basic_idle_timeout, onIdle: reload_from_idle}); idle_control = $(document).idle({idle: basic_idle_timeout, onIdle: reload_from_idle});
$(document).on("compose_started.zulip", compose_started_handler); $(document).on("compose_started.zulip", compose_started_handler);
} }
}; }
window.addEventListener("beforeunload", () => { window.addEventListener("beforeunload", () => {
// When navigating away from the page do not try to reload. // When navigating away from the page do not try to reload.
@ -335,5 +333,3 @@ window.addEventListener("beforeunload", () => {
blueslip.log("Setting reload_in_progress in beforeunload handler"); blueslip.log("Setting reload_in_progress in beforeunload handler");
reload_state.set_state_to_in_progress(); reload_state.set_state_to_in_progress();
}); });
window.reload = exports;

View File

@ -4,6 +4,7 @@ const _ = require("lodash");
const channel = require("./channel"); const channel = require("./channel");
const echo = require("./echo"); const echo = require("./echo");
const reload = require("./reload");
const reload_state = require("./reload_state"); const reload_state = require("./reload_state");
const server_events_dispatch = require("./server_events_dispatch"); const server_events_dispatch = require("./server_events_dispatch");
// Docs: https://zulip.readthedocs.io/en/latest/subsystems/events-system.html // Docs: https://zulip.readthedocs.io/en/latest/subsystems/events-system.html

View File

@ -5,6 +5,7 @@ import * as muting_ui from "./muting_ui";
import * as narrow_state from "./narrow_state"; import * as narrow_state from "./narrow_state";
import * as peer_data from "./peer_data"; import * as peer_data from "./peer_data";
import * as people from "./people"; import * as people from "./people";
import * as reload from "./reload";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as submessage from "./submessage"; import * as submessage from "./submessage";
import * as user_groups from "./user_groups"; import * as user_groups from "./user_groups";

View File

@ -2,6 +2,7 @@
const channel = require("./channel"); const channel = require("./channel");
const people = require("./people"); const people = require("./people");
const reload = require("./reload");
const reload_state = require("./reload_state"); const reload_state = require("./reload_state");
exports.send_message = function (request, on_success, error) { exports.send_message = function (request, on_success, error) {

View File

@ -21,6 +21,7 @@ const muting = require("./muting");
const people = require("./people"); const people = require("./people");
const pm_conversations = require("./pm_conversations"); const pm_conversations = require("./pm_conversations");
const pm_list = require("./pm_list"); const pm_list = require("./pm_list");
const reload = require("./reload");
const rows = require("./rows"); const rows = require("./rows");
const spoilers = require("./spoilers"); const spoilers = require("./spoilers");
const topic_list = require("./topic_list"); const topic_list = require("./topic_list");

View File

@ -2,6 +2,7 @@
const channel = require("./channel"); const channel = require("./channel");
const message_viewport = require("./message_viewport"); const message_viewport = require("./message_viewport");
const reload = require("./reload");
const unread_ui = require("./unread_ui"); const unread_ui = require("./unread_ui");
exports.mark_all_as_read = function () { exports.mark_all_as_read = function () {