js: Simplify more code using default parameters and destructuring.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-06-25 13:08:05 -07:00
committed by Tim Abbott
parent 166bfa4cf8
commit fa81ae3aa4
3 changed files with 9 additions and 13 deletions

View File

@@ -2,8 +2,7 @@ import $ from "jquery";
import render_loader from "../templates/loader.hbs";
export function make_indicator(outer_container, opts) {
opts = opts || {};
export function make_indicator(outer_container, {abs_positioned = false, text} = {}) {
let container = outer_container;
// TODO: We set white-space to 'nowrap' because under some
@@ -15,7 +14,7 @@ export function make_indicator(outer_container, opts) {
container.empty();
if (opts.abs_positioned !== undefined && opts.abs_positioned) {
if (abs_positioned) {
// Create some additional containers to facilitate absolutely
// positioned spinners.
const container_id = container.attr("id");
@@ -32,12 +31,12 @@ export function make_indicator(outer_container, opts) {
container.append(spinner_elem);
let text_width = 0;
if (opts.text !== undefined && opts.text !== "") {
if (text !== undefined) {
const text_elem = $('<span class="loading_indicator_text"></span>');
text_elem.text(opts.text);
text_elem.text(text);
container.append(text_elem);
// See note, below
if (!(opts.abs_positioned !== undefined && opts.abs_positioned)) {
if (!abs_positioned) {
text_width = 20 + text_elem.width();
}
}

View File

@@ -342,9 +342,7 @@ export function user_initiated_animate_scroll(scroll_amount) {
});
}
export function recenter_view(message, opts) {
opts = opts || {};
export function recenter_view(message, {from_scroll = false, force_center = false} = {}) {
// BarnOwl-style recentering: if the pointer is too high, move it to
// the 1/2 marks. If the pointer is too low, move it to the 1/7 mark.
// See keep_pointer_in_view() for related logic to keep the pointer onscreen.
@@ -361,7 +359,7 @@ export function recenter_view(message, opts) {
const is_above = message_top < top_threshold;
const is_below = message_bottom > bottom_threshold;
if (opts.from_scroll) {
if (from_scroll) {
// If the message you're trying to center on is already in view AND
// you're already trying to move in the direction of that message,
// don't try to recenter. This avoids disorienting jumps when the
@@ -375,7 +373,7 @@ export function recenter_view(message, opts) {
}
}
if (is_above || opts.force_center) {
if (is_above || force_center) {
set_message_position(message_top, message_height, viewport_info, 1 / 2);
} else if (is_below) {
set_message_position(message_top, message_height, viewport_info, 1 / 7);

View File

@@ -75,8 +75,7 @@ export function process_read_messages_event(message_ids) {
// Takes a list of messages and marks them as read.
// Skips any messages that are already marked as read.
export function notify_server_messages_read(messages, options) {
options = options || {};
export function notify_server_messages_read(messages, options = {}) {
messages = unread.get_unread_messages(messages);
if (messages.length === 0) {
return;