mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 09:27:43 +00:00
js: Convert _.find(a, …) to a.find(…).
And convert the corresponding function expressions to arrow style while we’re here. Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
committed by
Tim Abbott
parent
cdd774b790
commit
336a279005
@@ -98,9 +98,7 @@ exports.toggle = function (opts) {
|
|||||||
maybe_go_right: maybe_go_right,
|
maybe_go_right: maybe_go_right,
|
||||||
|
|
||||||
disable_tab: function (name) {
|
disable_tab: function (name) {
|
||||||
const value = _.find(opts.values, function (o) {
|
const value = opts.values.find(o => o.key === name);
|
||||||
return o.key === name;
|
|
||||||
});
|
|
||||||
|
|
||||||
const idx = opts.values.indexOf(value);
|
const idx = opts.values.indexOf(value);
|
||||||
meta.$ind_tab.eq(idx).addClass('disabled');
|
meta.$ind_tab.eq(idx).addClass('disabled');
|
||||||
@@ -118,9 +116,7 @@ exports.toggle = function (opts) {
|
|||||||
// go through the process of finding the correct tab for a given name,
|
// go through the process of finding the correct tab for a given name,
|
||||||
// and when found, select that one and provide the proper callback.
|
// and when found, select that one and provide the proper callback.
|
||||||
goto: function (name) {
|
goto: function (name) {
|
||||||
const value = _.find(opts.values, function (o) {
|
const value = opts.values.find(o => o.label === name || o.key === name);
|
||||||
return o.label === name || o.key === name;
|
|
||||||
});
|
|
||||||
|
|
||||||
const idx = opts.values.indexOf(value);
|
const idx = opts.values.indexOf(value);
|
||||||
|
|
||||||
|
|||||||
@@ -254,9 +254,9 @@ function get_alias_to_be_used(message_id, emoji_name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const user_id = page_params.user_id;
|
const user_id = page_params.user_id;
|
||||||
const reaction = _.find(message.reactions, function (reaction) {
|
const reaction = message.reactions.find(
|
||||||
return reaction.user.id === user_id && aliases.includes(reaction.emoji_name);
|
reaction => reaction.user.id === user_id && aliases.includes(reaction.emoji_name)
|
||||||
});
|
);
|
||||||
if (reaction) {
|
if (reaction) {
|
||||||
return reaction.emoji_name;
|
return reaction.emoji_name;
|
||||||
}
|
}
|
||||||
@@ -729,7 +729,7 @@ exports.register_click_handlers = function () {
|
|||||||
$("body").on("click", ".emoji-popover-tab-item", function (e) {
|
$("body").on("click", ".emoji-popover-tab-item", function (e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const offset = _.find(section_head_offsets, function (o) {
|
const offset = section_head_offsets.find(function (o) {
|
||||||
return o.section === $(this).attr("data-tab-name");
|
return o.section === $(this).attr("data-tab-name");
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
|||||||
@@ -530,7 +530,7 @@ Filter.prototype = {
|
|||||||
first_valid_id_from: function (msg_ids) {
|
first_valid_id_from: function (msg_ids) {
|
||||||
const predicate = this.predicate();
|
const predicate = this.predicate();
|
||||||
|
|
||||||
const first_id = _.find(msg_ids, function (msg_id) {
|
const first_id = msg_ids.find(msg_id => {
|
||||||
const message = message_store.get(msg_id);
|
const message = message_store.get(msg_id);
|
||||||
|
|
||||||
if (message === undefined) {
|
if (message === undefined) {
|
||||||
|
|||||||
@@ -219,9 +219,7 @@ exports.create = function (opts) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getByID: function (id) {
|
getByID: function (id) {
|
||||||
return _.find(store.pills, function (pill) {
|
return store.pills.find(pill => pill.id === id);
|
||||||
return pill.id === id;
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
items: function () {
|
items: function () {
|
||||||
|
|||||||
@@ -40,14 +40,12 @@ exports.set_name_in_mention_element = function (element, name) {
|
|||||||
exports.contains_backend_only_syntax = function (content) {
|
exports.contains_backend_only_syntax = function (content) {
|
||||||
// Try to guess whether or not a message has bugdown in it
|
// Try to guess whether or not a message has bugdown in it
|
||||||
// If it doesn't, we can immediately render it client-side
|
// If it doesn't, we can immediately render it client-side
|
||||||
const markedup = _.find(backend_only_markdown_re, function (re) {
|
const markedup = backend_only_markdown_re.find(re => re.test(content));
|
||||||
return re.test(content);
|
|
||||||
});
|
|
||||||
|
|
||||||
// If a realm filter doesn't start with some specified characters
|
// If a realm filter doesn't start with some specified characters
|
||||||
// then don't render it locally. It is workaround for the fact that
|
// then don't render it locally. It is workaround for the fact that
|
||||||
// javascript regex doesn't support lookbehind.
|
// javascript regex doesn't support lookbehind.
|
||||||
const false_filter_match = _.find(realm_filter_list, function (re) {
|
const false_filter_match = realm_filter_list.find(re => {
|
||||||
const pattern = /(?:[^\s'"\(,:<])/.source + re[0].source + /(?![\w])/.source;
|
const pattern = /(?:[^\s'"\(,:<])/.source + re[0].source + /(?![\w])/.source;
|
||||||
const regex = new RegExp(pattern);
|
const regex = new RegExp(pattern);
|
||||||
return regex.test(content);
|
return regex.test(content);
|
||||||
|
|||||||
@@ -180,9 +180,7 @@ MessageListData.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
first_unread_message_id: function () {
|
first_unread_message_id: function () {
|
||||||
const first_unread = _.find(this._items, function (message) {
|
const first_unread = this._items.find(message => unread.message_unread(message));
|
||||||
return unread.message_unread(message);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (first_unread) {
|
if (first_unread) {
|
||||||
return first_unread.id;
|
return first_unread.id;
|
||||||
|
|||||||
@@ -1156,12 +1156,12 @@ MessageListView.prototype = {
|
|||||||
// groups are merged etc.) , but we only call this from flows
|
// groups are merged etc.) , but we only call this from flows
|
||||||
// like message editing, so it's not a big performance
|
// like message editing, so it's not a big performance
|
||||||
// problem.
|
// problem.
|
||||||
return _.find(this._message_groups, function (message_group) {
|
return this._message_groups.find(
|
||||||
// Since we don't have a way to get a message group from
|
// Since we don't have a way to get a message group from
|
||||||
// the containing message container, we just do a search
|
// the containing message container, we just do a search
|
||||||
// to find it.
|
// to find it.
|
||||||
return message_group.message_group_id === message_group_id;
|
message_group => message_group.message_group_id === message_group_id
|
||||||
});
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
_rerender_header: function (message_containers) {
|
_rerender_header: function (message_containers) {
|
||||||
|
|||||||
@@ -64,9 +64,7 @@ function is_local_part(value, element) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.type_id_to_string = function (type_id) {
|
exports.type_id_to_string = function (type_id) {
|
||||||
const name = _.find(page_params.bot_types, function (bot_type) {
|
const name = page_params.bot_types.find(bot_type => bot_type.type_id === type_id).name;
|
||||||
return bot_type.type_id === type_id;
|
|
||||||
}).name;
|
|
||||||
return i18n.t(name);
|
return i18n.t(name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -90,9 +90,7 @@ exports.update_message = function (submsg) {
|
|||||||
message.submessages = [];
|
message.submessages = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const existing = _.find(message.submessages, function (sm) {
|
const existing = message.submessages.find(sm => sm.id === submsg.id);
|
||||||
return sm.id === submsg.id;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (existing !== undefined) {
|
if (existing !== undefined) {
|
||||||
blueslip.warn("Got submessage multiple times: " + submsg.id);
|
blueslip.warn("Got submessage multiple times: " + submsg.id);
|
||||||
|
|||||||
Reference in New Issue
Block a user