js: Avoid _.first, _.last, _.initial, _.tail.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg
2022-01-24 00:20:01 -08:00
committed by Tim Abbott
parent 42931e69e6
commit cc40352541
3 changed files with 17 additions and 19 deletions

View File

@@ -397,7 +397,7 @@ export class MessageListData {
} else {
// Any of the ids that we skipped over (due to them being local-only) might be the
// closest ID to the desired one, in case there is no exact match.
potential_closest_matches.unshift(_.last(potential_closest_matches) - 1);
potential_closest_matches.unshift(closest - 1);
let best_match = items[closest].id;
for (const potential_idx of potential_closest_matches) {

View File

@@ -437,8 +437,8 @@ export class MessageListView {
if (first_group === undefined || second_group === undefined) {
return false;
}
const last_msg_container = _.last(first_group.message_containers);
const first_msg_container = _.first(second_group.message_containers);
const last_msg_container = first_group.message_containers.at(-1);
const first_msg_container = second_group.message_containers[0];
// Join two groups into one.
if (
@@ -498,19 +498,19 @@ export class MessageListView {
let prev_msg_container;
if (where === "top") {
first_group = _.last(new_message_groups);
second_group = _.first(this._message_groups);
first_group = new_message_groups.at(-1);
second_group = this._message_groups[0];
} else {
first_group = _.last(this._message_groups);
second_group = _.first(new_message_groups);
first_group = this._message_groups.at(-1);
second_group = new_message_groups[0];
}
if (first_group) {
prev_msg_container = _.last(first_group.message_containers);
prev_msg_container = first_group.message_containers.at(-1);
}
if (second_group) {
curr_msg_container = _.first(second_group.message_containers);
curr_msg_container = second_group.message_containers[0];
}
const was_joined = this.join_message_groups(first_group, second_group);
@@ -536,7 +536,7 @@ export class MessageListView {
this._message_groups.shift();
this._message_groups.unshift(first_group);
new_message_groups = _.initial(new_message_groups);
new_message_groups = new_message_groups.slice(0, -1);
} else if (
!same_day(second_group.message_containers[0], first_group.message_containers[0])
) {
@@ -551,8 +551,8 @@ export class MessageListView {
if (was_joined) {
// rerender the last message
message_actions.rerender_messages_next_same_sender.push(prev_msg_container);
message_actions.append_messages = _.first(new_message_groups).message_containers;
new_message_groups = _.tail(new_message_groups);
message_actions.append_messages = new_message_groups[0].message_containers;
new_message_groups = new_message_groups.slice(1);
} else if (first_group !== undefined && second_group !== undefined) {
if (same_day(prev_msg_container, curr_msg_container)) {
clear_group_date_divider(second_group);
@@ -825,11 +825,10 @@ export class MessageListView {
restore_scroll_position();
const last_message_group = _.last(this._message_groups);
const last_message_group = this._message_groups.at(-1);
if (last_message_group !== undefined) {
list.last_message_historical = _.last(
last_message_group.message_containers,
).msg.historical;
list.last_message_historical =
last_message_group.message_containers.at(-1).msg.historical;
}
const stream_name = narrow_state.stream();

View File

@@ -1,5 +1,4 @@
import $ from "jquery";
import _ from "lodash";
import * as emoji from "../shared/js/emoji";
import render_message_reaction from "../templates/message_reaction.hbs";
@@ -172,8 +171,8 @@ function generate_title(emoji_name, user_ids) {
);
}
context.comma_separated_usernames = _.initial(usernames).join(", ");
context.last_username = _.last(usernames);
context.comma_separated_usernames = usernames.slice(0, -1).join(", ");
context.last_username = usernames.at(-1);
if (current_user_reacted) {
return $t(
{