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_night_logo": false,
"recent_topics": false,
"reload": false,
"reminder": false,
"resize": false,
"scroll_bar": false,

View File

@ -3,17 +3,22 @@
const {strict: assert} = require("assert");
const _ = require("lodash");
const rewiremock = require("rewiremock/node");
const {set_global, zrequire} = require("../zjsunit/namespace");
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) => {
assert.equal(delay, 0);
f();
});
rewiremock.enable();
const channel = zrequire("channel");
const default_stub_xhr = "default-stub-xhr";
@ -310,3 +315,4 @@ run_test("xhr_error_message", () => {
msg = "some message";
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 realm_icon = set_global("realm_icon", {});
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 settings_account = set_global("settings_account", {});
const settings_bots = set_global("settings_bots", {});

View File

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

View File

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

View File

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

View File

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

View File

@ -1,9 +1,7 @@
"use strict";
const {localstorage} = require("./localstorage");
const narrow_state = require("./narrow_state");
const reload_state = require("./reload_state");
const util = require("./util");
import {localstorage} from "./localstorage";
import * as narrow_state from "./narrow_state";
import * as reload_state from "./reload_state";
import * as util from "./util";
// Read https://zulip.readthedocs.io/en/latest/subsystems/hashchange-system.html
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
// done before the first call to get_events
exports.initialize = function () {
export function initialize() {
const location = window.location.toString();
const hash_fragment = location.slice(location.indexOf("#") + 1);
@ -173,7 +171,7 @@ exports.initialize = function () {
activity.set_new_user_input(false);
hashchange.changehash(vars.oldhash);
};
}
function do_reload_app(send_after_reload, save_pointer, save_narrow, save_compose, message) {
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);
}
exports.initiate = function (options) {
export function initiate(options) {
options = {
immediate: false,
save_pointer: true,
@ -324,7 +322,7 @@ exports.initiate = function (options) {
idle_control = $(document).idle({idle: basic_idle_timeout, onIdle: reload_from_idle});
$(document).on("compose_started.zulip", compose_started_handler);
}
};
}
window.addEventListener("beforeunload", () => {
// 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");
reload_state.set_state_to_in_progress();
});
window.reload = exports;

View File

@ -4,6 +4,7 @@ const _ = require("lodash");
const channel = require("./channel");
const echo = require("./echo");
const reload = require("./reload");
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

View File

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

View File

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

View File

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

View File

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