mirror of https://github.com/zulip/zulip.git
refactor: Use variables to get TypeScript type narrowing.
We also add an explicit undefined check for the these return value of the Map.get calls. This makes the TypeScript conversion diff cleaner.
This commit is contained in:
parent
2a21f626a7
commit
43da43701b
|
@ -9,9 +9,9 @@ const $ = require("../zjsunit/zjquery");
|
|||
const noop = () => {};
|
||||
|
||||
mock_esm("tippy.js", {
|
||||
default: (selector) => {
|
||||
$(selector)[0]._tippy = noop;
|
||||
$(selector)[0]._tippy.setContent = noop;
|
||||
default: (arg) => {
|
||||
arg._tippy = {setContent: noop};
|
||||
return arg._tippy;
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -90,11 +90,12 @@ function report_error(
|
|||
}
|
||||
|
||||
const key = ":" + msg + stack;
|
||||
const last_report_time = last_report_attempt.get(key);
|
||||
if (
|
||||
reported_errors.has(key) ||
|
||||
(last_report_attempt.has(key) &&
|
||||
(last_report_time !== undefined &&
|
||||
// Only try to report a given error once every 5 minutes
|
||||
Date.now() - last_report_attempt.get(key) <= 60 * 5 * 1000)
|
||||
Date.now() - last_report_time <= 60 * 5 * 1000)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -71,8 +71,9 @@ export function adjust_mac_shortcuts(key_elem_class, require_cmd_style) {
|
|||
}
|
||||
|
||||
for (const key of keys) {
|
||||
if (keys_map.get(key)) {
|
||||
key_text = key_text.replace(key, keys_map.get(key));
|
||||
const replace_key = keys_map.get(key);
|
||||
if (replace_key !== undefined) {
|
||||
key_text = key_text.replace(key, replace_key);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,10 +86,9 @@ export function adjust_mac_shortcuts(key_elem_class, require_cmd_style) {
|
|||
function set_password_toggle_label(password_selector, label, tippy_tooltips) {
|
||||
$(password_selector).attr("aria-label", label);
|
||||
if (tippy_tooltips) {
|
||||
if (!$(password_selector)[0]._tippy) {
|
||||
tippy(password_selector);
|
||||
}
|
||||
$(password_selector)[0]._tippy.setContent(label);
|
||||
const element = $(password_selector)[0];
|
||||
const tippy_instance = element._tippy ?? tippy(element);
|
||||
tippy_instance.setContent(label);
|
||||
} else {
|
||||
$(password_selector).attr("title", label);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue