mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 14:35:27 +00:00
js: Convert _.any(a, …), _.some(a, …) to a.some(…).
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
2285ee922e
commit
70ff164f89
@@ -38,9 +38,7 @@ people.add(me);
|
|||||||
people.initialize_current_user(me.user_id);
|
people.initialize_current_user(me.user_id);
|
||||||
|
|
||||||
function contains_sub(subs, sub) {
|
function contains_sub(subs, sub) {
|
||||||
return _.any(subs, function (s) {
|
return subs.some(s => s.name === sub.name);
|
||||||
return s.name === sub.name;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test('basics', () => {
|
run_test('basics', () => {
|
||||||
|
|||||||
@@ -151,9 +151,7 @@ const generate_emoji_picker_content = function (id) {
|
|||||||
emojis_used = reactions.get_emojis_used_by_user_for_message_id(id);
|
emojis_used = reactions.get_emojis_used_by_user_for_message_id(id);
|
||||||
}
|
}
|
||||||
for (const emoji_dict of emoji.emojis_by_name.values()) {
|
for (const emoji_dict of emoji.emojis_by_name.values()) {
|
||||||
emoji_dict.has_reacted = _.any(emoji_dict.aliases, function (alias) {
|
emoji_dict.has_reacted = emoji_dict.aliases.some(alias => emojis_used.includes(alias));
|
||||||
return emojis_used.includes(alias);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return render_emoji_popover_content({
|
return render_emoji_popover_content({
|
||||||
|
|||||||
@@ -362,19 +362,19 @@ Filter.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
has_negated_operand: function (operator, operand) {
|
has_negated_operand: function (operator, operand) {
|
||||||
return _.any(this._operators, function (elem) {
|
return this._operators.some(
|
||||||
return elem.negated && (elem.operator === operator && elem.operand === operand);
|
elem => elem.negated && (elem.operator === operator && elem.operand === operand)
|
||||||
});
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
has_operand: function (operator, operand) {
|
has_operand: function (operator, operand) {
|
||||||
return _.any(this._operators, function (elem) {
|
return this._operators.some(
|
||||||
return !elem.negated && (elem.operator === operator && elem.operand === operand);
|
elem => !elem.negated && (elem.operator === operator && elem.operand === operand)
|
||||||
});
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
has_operator: function (operator) {
|
has_operator: function (operator) {
|
||||||
return _.any(this._operators, function (elem) {
|
return this._operators.some(elem => {
|
||||||
if (elem.negated && !['search', 'has'].includes(elem.operator)) {
|
if (elem.negated && !['search', 'has'].includes(elem.operator)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -474,7 +474,7 @@ Filter.prototype = {
|
|||||||
return Filter.term_type(term) === 'pm-with';
|
return Filter.term_type(term) === 'pm-with';
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!_.any(terms, is_pm_with)) {
|
if (!terms.some(is_pm_with)) {
|
||||||
return terms;
|
return terms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -400,9 +400,7 @@ exports.group_pm_with_user_ids = function (message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const user_ids = message.display_recipient.map(recip => recip.id);
|
const user_ids = message.display_recipient.map(recip => recip.id);
|
||||||
const is_user_present = _.some(user_ids, function (user_id) {
|
const is_user_present = user_ids.some(user_id => exports.is_my_user_id(user_id));
|
||||||
return exports.is_my_user_id(user_id);
|
|
||||||
});
|
|
||||||
if (is_user_present) {
|
if (is_user_present) {
|
||||||
user_ids.sort();
|
user_ids.sort();
|
||||||
if (user_ids.length > 2) {
|
if (user_ids.length > 2) {
|
||||||
@@ -470,9 +468,7 @@ exports.update_email_in_reply_to = function (reply_to, user_id, new_email) {
|
|||||||
return reply_to;
|
return reply_to;
|
||||||
}
|
}
|
||||||
|
|
||||||
const needs_patch = _.any(persons, function (person) {
|
const needs_patch = persons.some(person => person.user_id === user_id);
|
||||||
return person.user_id === user_id;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!needs_patch) {
|
if (!needs_patch) {
|
||||||
return reply_to;
|
return reply_to;
|
||||||
@@ -791,11 +787,7 @@ exports.build_termlet_matcher = function (termlet) {
|
|||||||
}
|
}
|
||||||
const names = full_name.toLowerCase().split(' ');
|
const names = full_name.toLowerCase().split(' ');
|
||||||
|
|
||||||
return _.any(names, function (name) {
|
return names.some(name => name.startsWith(termlet));
|
||||||
if (name.startsWith(termlet)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -835,9 +827,7 @@ exports.filter_people_by_search_terms = function (users, search_terms) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return user emails that include search terms
|
// Return user emails that include search terms
|
||||||
const match = _.any(matchers, function (matcher) {
|
const match = matchers.some(matcher => matcher(user));
|
||||||
return matcher(user);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
filtered_users.set(person.user_id, true);
|
filtered_users.set(person.user_id, true);
|
||||||
|
|||||||
@@ -162,9 +162,7 @@ exports.poll_data_holder = function (is_my_poll, question, options) {
|
|||||||
|
|
||||||
// function to check whether option already exists
|
// function to check whether option already exists
|
||||||
self.is_option_present = function (data, latest_option) {
|
self.is_option_present = function (data, latest_option) {
|
||||||
return _.any(data, function (el) {
|
return data.some(el => el.option === latest_option);
|
||||||
return el.option === latest_option;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// function to add all options added along with the /poll command
|
// function to add all options added along with the /poll command
|
||||||
|
|||||||
@@ -441,12 +441,8 @@ exports.toggle_actions_popover = function (element, id) {
|
|||||||
|
|
||||||
const should_display_edit_history_option =
|
const should_display_edit_history_option =
|
||||||
message.edit_history &&
|
message.edit_history &&
|
||||||
_.any(
|
message.edit_history.some(entry => entry.prev_content !== undefined ||
|
||||||
message.edit_history,
|
util.get_edit_event_prev_topic(entry) !== undefined) &&
|
||||||
entry =>
|
|
||||||
entry.prev_content !== undefined ||
|
|
||||||
util.get_edit_event_prev_topic(entry) !== undefined
|
|
||||||
) &&
|
|
||||||
page_params.realm_allow_edit_history;
|
page_params.realm_allow_edit_history;
|
||||||
|
|
||||||
// Disabling this for /me messages is a temporary workaround
|
// Disabling this for /me messages is a temporary workaround
|
||||||
|
|||||||
@@ -32,11 +32,9 @@ exports.open_reactions_popover = function () {
|
|||||||
|
|
||||||
exports.current_user_has_reacted_to_emoji = function (message, emoji_code, type) {
|
exports.current_user_has_reacted_to_emoji = function (message, emoji_code, type) {
|
||||||
const user_id = page_params.user_id;
|
const user_id = page_params.user_id;
|
||||||
return _.any(message.reactions, function (r) {
|
return message.reactions.some(r => r.user.id === user_id &&
|
||||||
return r.user.id === user_id &&
|
|
||||||
r.reaction_type === type &&
|
r.reaction_type === type &&
|
||||||
r.emoji_code === emoji_code;
|
r.emoji_code === emoji_code);
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function get_message(message_id) {
|
function get_message(message_id) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ function make_person_highlighter(query) {
|
|||||||
|
|
||||||
function match_criteria(operators, criteria) {
|
function match_criteria(operators, criteria) {
|
||||||
const filter = new Filter(operators);
|
const filter = new Filter(operators);
|
||||||
return _.any(criteria, function (cr) {
|
return criteria.some(cr => {
|
||||||
if (_.has(cr, 'operand')) {
|
if (_.has(cr, 'operand')) {
|
||||||
return filter.has_operand(cr.operator, cr.operand);
|
return filter.has_operand(cr.operator, cr.operand);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,11 +17,7 @@ exports.vanilla_match = function (opts) {
|
|||||||
This is case insensitive.
|
This is case insensitive.
|
||||||
*/
|
*/
|
||||||
const val = opts.val.toLowerCase();
|
const val = opts.val.toLowerCase();
|
||||||
return _.any(opts.search_terms, function (term) {
|
return opts.search_terms.some(term => val.includes(term));
|
||||||
if (val.includes(term)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
window.search_util = exports;
|
window.search_util = exports;
|
||||||
|
|||||||
@@ -197,9 +197,9 @@ exports.populate_user_groups = function () {
|
|||||||
const blur_exceptions = _.without([".pill-container", ".name", ".description", ".input", ".delete"],
|
const blur_exceptions = _.without([".pill-container", ".name", ".description", ".input", ".delete"],
|
||||||
except_class);
|
except_class);
|
||||||
if ($(event.relatedTarget).closest('#user-groups #' + data.id).length) {
|
if ($(event.relatedTarget).closest('#user-groups #' + data.id).length) {
|
||||||
return _.some(blur_exceptions, function (class_name) {
|
return blur_exceptions.some(
|
||||||
return $(event.relatedTarget).closest(class_name).length;
|
class_name => $(event.relatedTarget).closest(class_name).length
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,13 +17,11 @@ function filter_streams_by_search(streams, search_term) {
|
|||||||
let search_terms = search_term.toLowerCase().split(",");
|
let search_terms = search_term.toLowerCase().split(",");
|
||||||
search_terms = search_terms.map(s => s.trim());
|
search_terms = search_terms.map(s => s.trim());
|
||||||
|
|
||||||
const filtered_streams = streams.filter(stream => _.any(search_terms, function (search_term) {
|
const filtered_streams = streams.filter(stream => search_terms.some(search_term => {
|
||||||
const lower_stream_name = stream.toLowerCase();
|
const lower_stream_name = stream.toLowerCase();
|
||||||
const cands = lower_stream_name.split(" ");
|
const cands = lower_stream_name.split(" ");
|
||||||
cands.push(lower_stream_name);
|
cands.push(lower_stream_name);
|
||||||
return _.any(cands, function (name) {
|
return cands.some(name => name.startsWith(search_term));
|
||||||
return name.startsWith(search_term);
|
|
||||||
});
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return filtered_streams;
|
return filtered_streams;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ const tictactoe_data_holder = function () {
|
|||||||
return square_values[i];
|
return square_values[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return _.any(lines, line_won) || _.all(board, filled);
|
return lines.some(line_won) || _.all(board, filled);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.get_widget_data = function () {
|
self.get_widget_data = function () {
|
||||||
|
|||||||
@@ -21,9 +21,7 @@ exports.task_data_holder = function () {
|
|||||||
|
|
||||||
self.check_task = {
|
self.check_task = {
|
||||||
task_exists: function (task) {
|
task_exists: function (task) {
|
||||||
const task_exists = _.any(all_tasks, function (item) {
|
const task_exists = all_tasks.some(item => item.task === task);
|
||||||
return item.task === task;
|
|
||||||
});
|
|
||||||
return task_exists;
|
return task_exists;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -80,9 +80,7 @@ exports.has_unconverted_data = function (pill_widget) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const items = pill_widget.items();
|
const items = pill_widget.items();
|
||||||
const has_unknown_items = _.any(items, function (item) {
|
const has_unknown_items = items.some(item => item.user_id === undefined);
|
||||||
return item.user_id === undefined;
|
|
||||||
});
|
|
||||||
|
|
||||||
return has_unknown_items;
|
return has_unknown_items;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ function query_matches_string(query, source_str, split_char) {
|
|||||||
// account, there might be 2 attrs: their full name and their email.
|
// account, there might be 2 attrs: their full name and their email.
|
||||||
// * split_char is the separator for this syntax (e.g. ' ').
|
// * split_char is the separator for this syntax (e.g. ' ').
|
||||||
exports.query_matches_source_attrs = (query, source, match_attrs, split_char) => {
|
exports.query_matches_source_attrs = (query, source, match_attrs, split_char) => {
|
||||||
return _.any(match_attrs, function (attr) {
|
return match_attrs.some(attr => {
|
||||||
const source_str = source[attr].toLowerCase();
|
const source_str = source[attr].toLowerCase();
|
||||||
return query_matches_string(query, source_str, split_char);
|
return query_matches_string(query, source_str, split_char);
|
||||||
});
|
});
|
||||||
@@ -151,9 +151,7 @@ exports.sort_emojis = function (objs, query) {
|
|||||||
|
|
||||||
function decent_match(name) {
|
function decent_match(name) {
|
||||||
const pieces = name.toLowerCase().split('_');
|
const pieces = name.toLowerCase().split('_');
|
||||||
return _.any(pieces, (piece) => {
|
return pieces.some(piece => piece.startsWith(lowerQuery));
|
||||||
return piece.startsWith(lowerQuery);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const popular_set = new Set(exports.popular_emojis);
|
const popular_set = new Set(exports.popular_emojis);
|
||||||
|
|||||||
Reference in New Issue
Block a user