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

Anders Kaseorgf9c4b5438e59
diff --git a/.eslintrc.json b/.eslintrc.json
index cf479714b84..58bd7a2307d 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -177,7 +177,6 @@
"loading": false,
"localStorage": false,
"local_message": false,
- "localstorage": false,
"location": false,
"markdown": false,
"message_edit": false,
diff --git a/frontend_tests/node_tests/drafts.js b/frontend_tests/node_tests/drafts.js
index 5a4560605b0..e51181d5772 100644
--- a/frontend_tests/node_tests/drafts.js
+++ b/frontend_tests/node_tests/drafts.js
@@ -7,7 +7,7 @@ const {set_global, zrequire, with_overrides} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
-const localstorage = zrequire("localstorage");
+const {localstorage} = zrequire("localstorage");
const drafts = zrequire("drafts");
const timerender = zrequire("timerender");
zrequire("stream_color");
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index 2ba69935999..133e0e40060 100644
--- a/static/js/bundles/app.js
+++ b/static/js/bundles/app.js
@@ -20,7 +20,6 @@ import "../keydown_util";
import "../rtl";
import "../fold_dict";
import "../scroll_util";
-import "../localstorage";
import "../drafts";
import "../input_pill";
import "../user_pill";
diff --git a/static/js/drafts.js b/static/js/drafts.js
index b770a2ee16a..10c35cc5656 100644
--- a/static/js/drafts.js
+++ b/static/js/drafts.js
@@ -5,6 +5,7 @@ const Handlebars = require("handlebars/runtime");
const render_draft_table_body = require("../templates/draft_table_body.hbs");
+const {localstorage} = require("./localstorage");
const people = require("./people");
const util = require("./util");
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index cb97eccf2bb..97b254100a4 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -51,7 +51,6 @@ declare let list_util: any;
declare let list_widget: any;
declare let loading: any;
declare let local_message: any;
-declare let localstorage: any;
declare let markdown: any;
declare let message_edit: any;
declare let message_events: any;
diff --git a/static/js/localstorage.js b/static/js/localstorage.js
index d2c52123f83..a01c6140e4a 100644
--- a/static/js/localstorage.js
+++ b/static/js/localstorage.js
@@ -1,5 +1,3 @@
-"use strict";
-
const ls = {
// parse JSON without throwing an error.
parseJSON(str) {
@@ -91,7 +89,7 @@ const ls = {
};
// return a new function instance that has instance-scoped variables.
-const localstorage = function () {
+export const localstorage = function () {
const _data = {
VERSION: 1,
expires: Number.POSITIVE_INFINITY,
@@ -179,6 +177,3 @@ localstorage.supported = function supports_localstorage() {
return false;
}
};
-
-module.exports = localstorage;
-window.localstorage = localstorage;
diff --git a/static/js/panels.js b/static/js/panels.js
index 650d7c5796a..33ddeda822a 100644
--- a/static/js/panels.js
+++ b/static/js/panels.js
@@ -1,5 +1,6 @@
"use strict";
+const {localstorage} = require("./localstorage");
const util = require("./util");
const resize_app = function () {
diff --git a/static/js/reload.js b/static/js/reload.js
index 1ba7cccbdca..671b5b589ce 100644
--- a/static/js/reload.js
+++ b/static/js/reload.js
@@ -1,6 +1,8 @@
"use strict";
+const {localstorage} = require("./localstorage");
const util = require("./util");
+
// Read https://zulip.readthedocs.io/en/latest/subsystems/hashchange-system.html
function preserve_state(send_after_reload, save_pointer, save_narrow, save_compose) {
if (!localstorage.supported()) {
diff --git a/static/js/ui.js b/static/js/ui.js
index 3cd8050708e..2ffb0ede595 100644
--- a/static/js/ui.js
+++ b/static/js/ui.js
@@ -2,6 +2,8 @@
const SimpleBar = require("simplebar/dist/simplebar");
+const {localstorage} = require("./localstorage");
+
// What, if anything, obscures the home tab?
exports.replace_emoji_with_text = function (element) {