mirror of https://github.com/zulip/zulip.git
js: Convert _.map(a, …) to a.map(…).
And convert the corresponding function expressions to arrow style while we’re here. import * as babelParser from "recast/parsers/babel"; import * as recast from "recast"; import * as tsParser from "recast/parsers/typescript"; import { builders as b, namedTypes as n } from "ast-types"; import K from "ast-types/gen/kinds"; import fs from "fs"; import path from "path"; import process from "process"; const checkExpression = (node: n.Node): node is K.ExpressionKind => n.Expression.check(node); for (const file of process.argv.slice(2)) { console.log("Parsing", file); const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), { parser: path.extname(file) === ".ts" ? tsParser : babelParser, }); let changed = false; recast.visit(ast, { visitCallExpression(path) { const { callee, arguments: args } = path.node; if ( n.MemberExpression.check(callee) && !callee.computed && n.Identifier.check(callee.object) && callee.object.name === "_" && n.Identifier.check(callee.property) && callee.property.name === "map" && args.length === 2 && checkExpression(args[0]) && checkExpression(args[1]) ) { const [arr, fn] = args; path.replace( b.callExpression(b.memberExpression(arr, b.identifier("map")), [ n.FunctionExpression.check(fn) || n.ArrowFunctionExpression.check(fn) ? b.arrowFunctionExpression( fn.params, n.BlockStatement.check(fn.body) && fn.body.body.length === 1 && n.ReturnStatement.check(fn.body.body[0]) ? fn.body.body[0].argument || b.identifier("undefined") : fn.body ) : fn, ]) ); changed = true; } this.traverse(path); }, }); if (changed) { console.log("Writing", file); fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" }); } } Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
parent
719546641f
commit
ac7b09d57e
|
@ -35,7 +35,7 @@ people.add(steve);
|
|||
people.initialize_current_user(me.user_id);
|
||||
|
||||
function assert_same_operators(result, terms) {
|
||||
terms = _.map(terms, function (term) {
|
||||
terms = terms.map(term => {
|
||||
// If negated flag is undefined, we explicitly
|
||||
// set it to false.
|
||||
let negated = term.negated;
|
||||
|
@ -508,9 +508,10 @@ run_test('canonicalizations', () => {
|
|||
});
|
||||
|
||||
function get_predicate(operators) {
|
||||
operators = _.map(operators, function (op) {
|
||||
return {operator: op[0], operand: op[1]};
|
||||
});
|
||||
operators = operators.map(op => ({
|
||||
operator: op[0],
|
||||
operand: op[1],
|
||||
}));
|
||||
return new Filter(operators).predicate();
|
||||
}
|
||||
|
||||
|
|
|
@ -268,7 +268,7 @@ run_test('sorting', () => {
|
|||
};
|
||||
|
||||
function html_for(people) {
|
||||
return _.map(people, opts.modifier).join('');
|
||||
return people.map(opts.modifier).join('');
|
||||
}
|
||||
|
||||
list_render.create(container, list, opts);
|
||||
|
|
|
@ -132,9 +132,9 @@ function config_process_results(messages) {
|
|||
}
|
||||
|
||||
function message_range(start, end) {
|
||||
return _.map(_.range(start, end), function (idx) {
|
||||
return { id: idx };
|
||||
});
|
||||
return _.range(start, end).map(idx => ({
|
||||
id: idx,
|
||||
}));
|
||||
}
|
||||
|
||||
const initialize_data = {
|
||||
|
|
|
@ -22,7 +22,7 @@ function make_msg(msg_id) {
|
|||
}
|
||||
|
||||
function make_msgs(msg_ids) {
|
||||
return _.map(msg_ids, make_msg);
|
||||
return msg_ids.map(make_msg);
|
||||
}
|
||||
|
||||
function assert_contents(mld, msg_ids) {
|
||||
|
|
|
@ -167,9 +167,7 @@ run_test('merge_message_groups', () => {
|
|||
}
|
||||
|
||||
function extract_message_ids(lst) {
|
||||
return _.map(lst, (item) => {
|
||||
return item.msg.id;
|
||||
});
|
||||
return lst.map(item => item.msg.id);
|
||||
}
|
||||
|
||||
function assert_message_list_equal(list1, list2) {
|
||||
|
@ -184,8 +182,8 @@ run_test('merge_message_groups', () => {
|
|||
}
|
||||
|
||||
function assert_message_groups_list_equal(list1, list2) {
|
||||
const ids1 = _.map(list1, extract_group);
|
||||
const ids2 = _.map(list2, extract_group);
|
||||
const ids1 = list1.map(extract_group);
|
||||
const ids2 = list2.map(extract_group);
|
||||
assert(ids1.length);
|
||||
assert.deepEqual(ids1, ids2);
|
||||
}
|
||||
|
@ -547,11 +545,9 @@ run_test('render_windows', () => {
|
|||
let messages;
|
||||
|
||||
function reset_list(opts) {
|
||||
messages = _.map(_.range(opts.count), function (i) {
|
||||
return {
|
||||
messages = _.range(opts.count).map(i => ({
|
||||
id: i,
|
||||
};
|
||||
});
|
||||
}));
|
||||
list.selected_idx = function () { return 0; };
|
||||
list.clear();
|
||||
|
||||
|
|
|
@ -68,13 +68,11 @@ global.people.initialize_current_user(me.user_id);
|
|||
|
||||
function convert_recipients(people) {
|
||||
// Display_recipient uses `id` for user_ids.
|
||||
return _.map(people, (p) => {
|
||||
return {
|
||||
return people.map(p => ({
|
||||
email: p.email,
|
||||
id: p.user_id,
|
||||
full_name: p.full_name,
|
||||
};
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
run_test('add_message_metadata', () => {
|
||||
|
|
|
@ -15,9 +15,10 @@ set_global('page_params', {
|
|||
zrequire('narrow');
|
||||
|
||||
function set_filter(operators) {
|
||||
operators = _.map(operators, function (op) {
|
||||
return {operator: op[0], operand: op[1]};
|
||||
});
|
||||
operators = operators.map(op => ({
|
||||
operator: op[0],
|
||||
operand: op[1],
|
||||
}));
|
||||
narrow_state.set_current_filter(new Filter(operators));
|
||||
}
|
||||
|
||||
|
|
|
@ -10,9 +10,10 @@ set_global('blueslip', global.make_zblueslip());
|
|||
set_global('page_params', {});
|
||||
|
||||
function set_filter(operators) {
|
||||
operators = _.map(operators, function (op) {
|
||||
return {operator: op[0], operand: op[1]};
|
||||
});
|
||||
operators = operators.map(op => ({
|
||||
operator: op[0],
|
||||
operand: op[1],
|
||||
}));
|
||||
narrow_state.set_current_filter(new Filter(operators));
|
||||
}
|
||||
|
||||
|
|
|
@ -82,9 +82,7 @@ run_test('get_list_info unreads', () => {
|
|||
// Going forward, we just stub get_recent_names
|
||||
// for simpler test setup.
|
||||
topic_data.get_recent_names = () => {
|
||||
return _.map(_.range(15), (i) => {
|
||||
return 'topic ' + i;
|
||||
});
|
||||
return _.range(15).map(i => 'topic ' + i);
|
||||
};
|
||||
|
||||
const unread_cnt = {};
|
||||
|
@ -111,7 +109,7 @@ run_test('get_list_info unreads', () => {
|
|||
assert.equal(list_info.num_possible_topics, 15);
|
||||
|
||||
assert.deepEqual(
|
||||
_.map(list_info.items, (li) => li.topic_name),
|
||||
list_info.items.map(li => li.topic_name),
|
||||
[
|
||||
'topic 0',
|
||||
'topic 1',
|
||||
|
@ -131,7 +129,7 @@ run_test('get_list_info unreads', () => {
|
|||
assert.equal(list_info.num_possible_topics, 15);
|
||||
|
||||
assert.deepEqual(
|
||||
_.map(list_info.items, (li) => li.topic_name),
|
||||
list_info.items.map(li => li.topic_name),
|
||||
[
|
||||
'topic 0',
|
||||
'topic 1',
|
||||
|
@ -158,7 +156,7 @@ run_test('get_list_info unreads', () => {
|
|||
assert.equal(list_info.num_possible_topics, 15);
|
||||
|
||||
assert.deepEqual(
|
||||
_.map(list_info.items, (li) => li.topic_name),
|
||||
list_info.items.map(li => li.topic_name),
|
||||
[
|
||||
'topic 0',
|
||||
'topic 1',
|
||||
|
|
|
@ -24,8 +24,8 @@ let next_id = 0;
|
|||
|
||||
function assertSameEmails(lst1, lst2) {
|
||||
assert.deepEqual(
|
||||
_.map(lst1, (r) => r.email),
|
||||
_.map(lst2, (r) => r.email)
|
||||
lst1.map(r => r.email),
|
||||
lst2.map(r => r.email)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -209,9 +209,7 @@ function get_typeahead_result(query, current_stream, current_topic) {
|
|||
current_stream,
|
||||
current_topic
|
||||
);
|
||||
return _.map(result, function (person) {
|
||||
return person.email;
|
||||
});
|
||||
return result.map(person => person.email);
|
||||
}
|
||||
|
||||
run_test('sort_recipients', () => {
|
||||
|
@ -363,9 +361,7 @@ run_test('sort_recipients dup bots', () => {
|
|||
const dup_objects = matches.concat([a_bot]);
|
||||
|
||||
const recipients = th.sort_recipients(dup_objects, "b", "", "");
|
||||
const recipients_email = _.map(recipients, function (person) {
|
||||
return person.email;
|
||||
});
|
||||
const recipients_email = recipients.map(person => person.email);
|
||||
const expected = [
|
||||
'b_bot@example.com',
|
||||
'b_user_3@zulip.net',
|
||||
|
@ -402,9 +398,7 @@ run_test('sort_recipients subscribers', () => {
|
|||
// b_user_2 is a subscriber and b_user_1 is not.
|
||||
const small_matches = [b_user_2, b_user_1];
|
||||
const recipients = th.sort_recipients(small_matches, "b", "Dev", "Dev Topic");
|
||||
const recipients_email = _.map(recipients, function (person) {
|
||||
return person.email;
|
||||
});
|
||||
const recipients_email = recipients.map(person => person.email);
|
||||
const expected = [
|
||||
'b_user_2@zulip.net',
|
||||
'b_user_1@zulip.net',
|
||||
|
@ -417,9 +411,7 @@ run_test('sort_recipients pm partners', () => {
|
|||
// both are not subscribered to the stream Linux.
|
||||
const small_matches = [b_user_3, b_user_2];
|
||||
const recipients = th.sort_recipients(small_matches, "b", "Linux", "Linux Topic");
|
||||
const recipients_email = _.map(recipients, function (person) {
|
||||
return person.email;
|
||||
});
|
||||
const recipients_email = recipients.map(person => person.email);
|
||||
const expected = [
|
||||
'b_user_3@zulip.net',
|
||||
'b_user_2@zulip.net',
|
||||
|
@ -438,7 +430,7 @@ run_test('sort broadcast mentions', () => {
|
|||
'');
|
||||
|
||||
assert.deepEqual(
|
||||
_.map(results, (r) => r.email),
|
||||
results.map(r => r.email),
|
||||
['all', 'everyone', 'stream']
|
||||
);
|
||||
|
||||
|
@ -455,7 +447,7 @@ run_test('sort broadcast mentions', () => {
|
|||
'');
|
||||
|
||||
assert.deepEqual(
|
||||
_.map(results2, (r) => r.email),
|
||||
results2.map(r => r.email),
|
||||
['all',
|
||||
'everyone',
|
||||
'stream',
|
||||
|
@ -715,9 +707,7 @@ run_test('sort_slash_commands', () => {
|
|||
|
||||
run_test('sort_recipientbox_typeahead', () => {
|
||||
let recipients = th.sort_recipientbox_typeahead("b, a", matches, ""); // search "a"
|
||||
let recipients_email = _.map(recipients, function (person) {
|
||||
return person.email;
|
||||
});
|
||||
let recipients_email = recipients.map(person => person.email);
|
||||
assert.deepEqual(recipients_email, [
|
||||
'a_user@zulip.org', // matches "a"
|
||||
'a_bot@zulip.com', // matches "a"
|
||||
|
@ -729,9 +719,7 @@ run_test('sort_recipientbox_typeahead', () => {
|
|||
]);
|
||||
|
||||
recipients = th.sort_recipientbox_typeahead("b, a, b", matches, ""); // search "b"
|
||||
recipients_email = _.map(recipients, function (person) {
|
||||
return person.email;
|
||||
});
|
||||
recipients_email = recipients.map(person => person.email);
|
||||
assert.deepEqual(recipients_email, [
|
||||
'b_bot@example.com',
|
||||
'b_user_3@zulip.net',
|
||||
|
|
|
@ -97,9 +97,7 @@ function make_child(i, name) {
|
|||
}
|
||||
|
||||
function make_children(lst) {
|
||||
return _.map(lst, (i) => {
|
||||
return make_child(i, 'foo' + i);
|
||||
});
|
||||
return lst.map(i => make_child(i, 'foo' + i));
|
||||
}
|
||||
|
||||
run_test('children', () => {
|
||||
|
|
|
@ -17,7 +17,7 @@ exports.t = function (str, context) {
|
|||
*/
|
||||
const keyword_regex = /__(- )?(\w)+__/g;
|
||||
const keys_in_str = str.match(keyword_regex) || [];
|
||||
const substitutions = _.map(keys_in_str, function (key) {
|
||||
const substitutions = keys_in_str.map(key => {
|
||||
let prefix_length;
|
||||
if (key.startsWith("__- ")) {
|
||||
prefix_length = 4;
|
||||
|
|
|
@ -118,7 +118,7 @@ function diff_strings(string_0, string_1) {
|
|||
const emphasize_codes = (string) => {
|
||||
return "\u001b[34m" + string.slice(0, 1) + "\u001b[0m" + string.slice(1);
|
||||
};
|
||||
output_lines = _.map(output_lines, emphasize_codes);
|
||||
output_lines = output_lines.map(emphasize_codes);
|
||||
|
||||
return output_lines.join("\n");
|
||||
}
|
||||
|
|
|
@ -524,13 +524,9 @@ exports.make_zjquery = function (opts) {
|
|||
|
||||
zjquery.state = function () {
|
||||
// useful for debugging
|
||||
let res = _.map(elems, function (v) {
|
||||
return v.debug();
|
||||
});
|
||||
let res = elems.map(v => v.debug());
|
||||
|
||||
res = _.map(res, function (v) {
|
||||
return [v.selector, v.value, v.shown];
|
||||
});
|
||||
res = res.map(v => [v.selector, v.value, v.shown]);
|
||||
|
||||
res.sort();
|
||||
|
||||
|
|
|
@ -128,15 +128,13 @@ exports.get_huddles = function () {
|
|||
};
|
||||
|
||||
function huddle_split(huddle) {
|
||||
return _.map(huddle.split(','), function (s) {
|
||||
return parseInt(s, 10);
|
||||
});
|
||||
return huddle.split(',').map(s => parseInt(s, 10));
|
||||
}
|
||||
|
||||
exports.full_huddle_name = function (huddle) {
|
||||
const user_ids = huddle_split(huddle);
|
||||
|
||||
const names = _.map(user_ids, function (user_id) {
|
||||
const names = user_ids.map(user_id => {
|
||||
const person = people.get_by_user_id(user_id);
|
||||
return person.full_name;
|
||||
});
|
||||
|
@ -148,7 +146,7 @@ exports.short_huddle_name = function (huddle) {
|
|||
const user_ids = huddle_split(huddle);
|
||||
|
||||
const num_to_show = 3;
|
||||
let names = _.map(user_ids, function (user_id) {
|
||||
let names = user_ids.map(user_id => {
|
||||
const person = people.get_by_user_id(user_id);
|
||||
return person.full_name;
|
||||
});
|
||||
|
@ -246,15 +244,13 @@ exports.update_huddles = function () {
|
|||
return;
|
||||
}
|
||||
|
||||
const group_pms = _.map(huddles, function (huddle) {
|
||||
return {
|
||||
const group_pms = huddles.map(huddle => ({
|
||||
user_ids_string: huddle,
|
||||
name: exports.full_huddle_name(huddle),
|
||||
href: hash_util.huddle_with_uri(huddle),
|
||||
fraction_present: buddy_data.huddle_fraction_present(huddle),
|
||||
short_name: exports.short_huddle_name(huddle),
|
||||
};
|
||||
});
|
||||
}));
|
||||
|
||||
const html = render_group_pms({group_pms: group_pms});
|
||||
ui.get_content_element($('#group-pms')).html(html);
|
||||
|
|
|
@ -26,9 +26,7 @@ exports.add = function bot_data__add(bot) {
|
|||
const clean_bot = _.pick(bot, bot_fields);
|
||||
bots.set(bot.user_id, clean_bot);
|
||||
set_can_admin(clean_bot);
|
||||
const clean_services = _.map(bot.services, function (service) {
|
||||
return _.pick(service, services_fields);
|
||||
});
|
||||
const clean_services = bot.services.map(service => _.pick(service, services_fields));
|
||||
services.set(bot.user_id, clean_services);
|
||||
|
||||
send_change_event();
|
||||
|
|
|
@ -118,13 +118,9 @@ function filter_user_ids(filter_text, user_ids) {
|
|||
user_ids = _.reject(user_ids, people.is_my_user_id);
|
||||
|
||||
let search_terms = filter_text.toLowerCase().split(/[|,]+/);
|
||||
search_terms = _.map(search_terms, function (s) {
|
||||
return s.trim();
|
||||
});
|
||||
search_terms = search_terms.map(s => s.trim());
|
||||
|
||||
const persons = _.map(user_ids, function (user_id) {
|
||||
return people.get_by_user_id(user_id);
|
||||
});
|
||||
const persons = user_ids.map(user_id => people.get_by_user_id(user_id));
|
||||
|
||||
const user_id_dict = people.filter_people_by_search_terms(persons, search_terms);
|
||||
return Array.from(user_id_dict.keys());
|
||||
|
@ -330,7 +326,7 @@ exports.get_filtered_and_sorted_user_ids = function (filter_text) {
|
|||
};
|
||||
|
||||
exports.get_items_for_users = function (user_ids) {
|
||||
const user_info = _.map(user_ids, exports.info_for);
|
||||
const user_info = user_ids.map(exports.info_for);
|
||||
compose_fade.update_user_info(user_info, fade_config);
|
||||
return user_info;
|
||||
};
|
||||
|
|
|
@ -92,7 +92,7 @@ exports.compute_placeholder_text = function (opts) {
|
|||
// For Private Messages
|
||||
if (opts.private_message_recipient) {
|
||||
const recipient_list = opts.private_message_recipient.split(",");
|
||||
const recipient_names = _.map(recipient_list, (recipient) => {
|
||||
const recipient_names = recipient_list.map(recipient => {
|
||||
const user = people.get_by_email(recipient);
|
||||
return user.full_name;
|
||||
}).join(", ");
|
||||
|
|
|
@ -325,19 +325,22 @@ exports.tokenize_compose_str = function (s) {
|
|||
};
|
||||
|
||||
exports.broadcast_mentions = function () {
|
||||
return _.map(['all', 'everyone', 'stream'], function (mention, idx) {
|
||||
return {
|
||||
return ['all', 'everyone', 'stream'].map((mention, idx) => ({
|
||||
special_item_text: i18n.t("__wildcard_mention_token__ (Notify stream)",
|
||||
{wildcard_mention_token: mention}),
|
||||
|
||||
email: mention,
|
||||
|
||||
// Always sort above, under the assumption that names will
|
||||
// be longer and only contain "all" as a substring.
|
||||
pm_recipient_count: Infinity,
|
||||
|
||||
full_name: mention,
|
||||
is_broadcast: true,
|
||||
idx: idx, // used for sorting
|
||||
};
|
||||
});
|
||||
|
||||
// used for sorting
|
||||
idx: idx,
|
||||
}));
|
||||
};
|
||||
|
||||
function filter_mention_name(current_token) {
|
||||
|
|
|
@ -228,7 +228,7 @@ exports.format_draft = function (draft) {
|
|||
};
|
||||
} else {
|
||||
const emails = util.extract_pm_recipients(draft.private_message_recipient);
|
||||
const recipients = _.map(emails, function (email) {
|
||||
const recipients = emails.map(email => {
|
||||
email = email.trim();
|
||||
const person = people.get_by_email(email);
|
||||
if (person !== undefined) {
|
||||
|
@ -305,7 +305,7 @@ exports.launch = function () {
|
|||
return draft_b.updatedAt - draft_a.updatedAt;
|
||||
});
|
||||
|
||||
const sorted_formatted_drafts = _.filter(_.map(sorted_raw_drafts, exports.format_draft));
|
||||
const sorted_formatted_drafts = _.filter(sorted_raw_drafts.map(exports.format_draft));
|
||||
|
||||
return sorted_formatted_drafts;
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ exports.build_display_recipient = function (message) {
|
|||
const emails = util.extract_pm_recipients(message.private_message_recipient);
|
||||
|
||||
let sender_in_display_recipients = false;
|
||||
const display_recipient = _.map(emails, function (email) {
|
||||
const display_recipient = emails.map(email => {
|
||||
email = email.trim();
|
||||
const person = people.get_by_email(email);
|
||||
if (person === undefined) {
|
||||
|
|
|
@ -42,9 +42,7 @@ function wrap_quote(text) {
|
|||
// beginning of each line
|
||||
for (const paragraph of paragraphs) {
|
||||
const lines = paragraph.split('\n');
|
||||
quoted_paragraphs.push(_.map(
|
||||
_.reject(lines, function (line) { return line === ''; }),
|
||||
function (line) { return '> ' + line; }).join('\n'));
|
||||
quoted_paragraphs.push(_.reject(lines, function (line) { return line === ''; }).map(line => '> ' + line).join('\n'));
|
||||
}
|
||||
|
||||
return quoted_paragraphs.join('\n\n');
|
||||
|
|
|
@ -310,7 +310,7 @@ Filter.parse = function (str) {
|
|||
might need to support multiple operators of the same type.
|
||||
*/
|
||||
Filter.unparse = function (operators) {
|
||||
const parts = _.map(operators, function (elem) {
|
||||
const parts = operators.map(elem => {
|
||||
|
||||
if (elem.operator === 'search') {
|
||||
// Search terms are the catch-all case.
|
||||
|
@ -481,13 +481,11 @@ Filter.prototype = {
|
|||
},
|
||||
|
||||
_canonicalize_operators: function (operators_mixed_case) {
|
||||
return _.map(operators_mixed_case, function (tuple) {
|
||||
return Filter.canonicalize_term(tuple);
|
||||
});
|
||||
return operators_mixed_case.map(tuple => Filter.canonicalize_term(tuple));
|
||||
},
|
||||
|
||||
filter_with_new_topic: function (new_topic) {
|
||||
const terms = _.map(this._operators, function (term) {
|
||||
const terms = this._operators.map(term => {
|
||||
const new_term = _.clone(term);
|
||||
if (new_term.operator === 'topic' && !new_term.negated) {
|
||||
new_term.operand = new_topic;
|
||||
|
@ -503,7 +501,7 @@ Filter.prototype = {
|
|||
|
||||
sorted_term_types: function () {
|
||||
const terms = this._operators;
|
||||
const term_types = _.map(terms, Filter.term_type);
|
||||
const term_types = terms.map(Filter.term_type);
|
||||
const sorted_terms = Filter.sorted_term_types(term_types);
|
||||
return sorted_terms;
|
||||
},
|
||||
|
@ -712,7 +710,7 @@ function describe_unescaped(operators) {
|
|||
}
|
||||
}
|
||||
|
||||
const more_parts = _.map(operators, function (elem) {
|
||||
const more_parts = operators.map(elem => {
|
||||
const operand = elem.operand;
|
||||
const canonicalized_operator = Filter.canonicalize_operator(elem.operator);
|
||||
if (canonicalized_operator === 'is') {
|
||||
|
|
|
@ -175,7 +175,7 @@ exports.relevant_recipient_bars = function () {
|
|||
return [];
|
||||
}
|
||||
|
||||
const items = _.map(elems, function (elem, i) {
|
||||
const items = elems.map((elem, i) => {
|
||||
let date_html;
|
||||
let need_frb;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ exports.set_up_toggler = function () {
|
|||
const elem = exports.toggler.get();
|
||||
elem.addClass('large allow-overflow');
|
||||
|
||||
const modals = _.map(opts.values, function (item) {
|
||||
const modals = opts.values.map(item => {
|
||||
const key = item.key; // e.g. message-formatting
|
||||
const modal = $('#' + key).find('.modal-body');
|
||||
return modal;
|
||||
|
|
|
@ -34,7 +34,7 @@ function maybe_add_narrowed_messages(messages, msg_list) {
|
|||
// edited in between when they sent the message and when
|
||||
// we hear back from the server and can echo the new
|
||||
// message. Arguably, it's counterproductive complexity.
|
||||
new_messages = _.map(new_messages, message_store.add_message_metadata);
|
||||
new_messages = new_messages.map(message_store.add_message_metadata);
|
||||
|
||||
message_util.add_new_messages(new_messages, msg_list);
|
||||
unread_ops.process_visible();
|
||||
|
@ -54,7 +54,7 @@ function maybe_add_narrowed_messages(messages, msg_list) {
|
|||
|
||||
|
||||
exports.insert_new_messages = function insert_new_messages(messages, sent_by_this_client) {
|
||||
messages = _.map(messages, message_store.add_message_metadata);
|
||||
messages = messages.map(message_store.add_message_metadata);
|
||||
|
||||
unread.process_loaded_messages(messages);
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ function process_result(data, opts) {
|
|||
}
|
||||
|
||||
_.each(messages, message_store.set_message_booleans);
|
||||
messages = _.map(messages, message_store.add_message_metadata);
|
||||
messages = messages.map(message_store.add_message_metadata);
|
||||
|
||||
// In case any of the newly fetched messages are new, add them to
|
||||
// our unread data structures. It's important that this run even
|
||||
|
@ -118,7 +118,7 @@ function handle_operators_supporting_id_based_api(data) {
|
|||
}
|
||||
|
||||
data.narrow = JSON.parse(data.narrow);
|
||||
data.narrow = _.map(data.narrow, function (filter) {
|
||||
data.narrow = data.narrow.map(filter => {
|
||||
if (operators_supporting_ids.includes(filter.operator)) {
|
||||
filter.operand = people.emails_strings_to_user_ids_array(filter.operand);
|
||||
}
|
||||
|
|
|
@ -19,9 +19,7 @@ exports.send_read = (function () {
|
|||
const real_msgs = _.filter(queue, function (msg) {
|
||||
return !msg.locally_echoed;
|
||||
});
|
||||
const real_msg_ids = _.map(real_msgs, function (msg) {
|
||||
return msg.id;
|
||||
});
|
||||
const real_msg_ids = real_msgs.map(msg => msg.id);
|
||||
|
||||
if (real_msg_ids.length === 0) {
|
||||
setTimeout(start, 100);
|
||||
|
|
|
@ -684,7 +684,7 @@ MessageListView.prototype = {
|
|||
// all messages lists. To prevent having both list views overwriting
|
||||
// each others data we will make a new message object to add data to
|
||||
// for rendering.
|
||||
const message_containers = _.map(messages, function (message) {
|
||||
const message_containers = messages.map(message => {
|
||||
if (message.starred) {
|
||||
message.starred_status = i18n.t("Unstar");
|
||||
} else {
|
||||
|
@ -793,9 +793,7 @@ MessageListView.prototype = {
|
|||
if (message_actions.append_messages.length > 0) {
|
||||
last_message_row = table.find('.message_row').last().expectOne();
|
||||
last_group_row = rows.get_message_recipient_row(last_message_row);
|
||||
dom_messages = $(_.map(message_actions.append_messages, function (message_container) {
|
||||
return self._get_message_template(message_container);
|
||||
}).join('')).filter('.message_row');
|
||||
dom_messages = $(message_actions.append_messages.map(message_container => self._get_message_template(message_container)).join('')).filter('.message_row');
|
||||
|
||||
self._post_process(dom_messages);
|
||||
last_group_row.append(dom_messages);
|
||||
|
@ -1233,9 +1231,7 @@ MessageListView.prototype = {
|
|||
const self = this;
|
||||
|
||||
// Convert messages to list messages
|
||||
let message_containers = _.map(messages, function (message) {
|
||||
return self.message_containers[message.id];
|
||||
});
|
||||
let message_containers = messages.map(message => self.message_containers[message.id]);
|
||||
// We may not have the message_container if the stream or topic was muted
|
||||
message_containers = _.reject(message_containers, function (message_container) {
|
||||
return message_container === undefined;
|
||||
|
|
|
@ -39,7 +39,7 @@ exports.get_pm_emails = function (message) {
|
|||
}
|
||||
|
||||
const user_ids = people.pm_with_user_ids(message);
|
||||
const emails = _.map(user_ids, email).sort();
|
||||
const emails = user_ids.map(email).sort();
|
||||
|
||||
return emails.join(', ');
|
||||
};
|
||||
|
@ -56,7 +56,7 @@ exports.get_pm_full_names = function (message) {
|
|||
}
|
||||
|
||||
const user_ids = people.pm_with_user_ids(message);
|
||||
const names = _.map(user_ids, name).sort();
|
||||
const names = user_ids.map(name).sort();
|
||||
|
||||
return names.join(', ');
|
||||
};
|
||||
|
|
|
@ -115,8 +115,7 @@ exports.activate = function (raw_operators, opts) {
|
|||
notifications.hide_history_limit_message();
|
||||
$(".all-messages-search-caution").hide();
|
||||
|
||||
blueslip.debug("Narrowed", {operators: _.map(operators,
|
||||
function (e) { return e.operator; }),
|
||||
blueslip.debug("Narrowed", {operators: operators.map(e => e.operator),
|
||||
trigger: opts ? opts.trigger : undefined,
|
||||
previous_id: current_msg_list.selected_id()});
|
||||
|
||||
|
|
|
@ -38,9 +38,7 @@ exports.init = function () {
|
|||
exports.init();
|
||||
|
||||
function split_to_ints(lst) {
|
||||
return _.map(lst.split(','), function (s) {
|
||||
return parseInt(s, 10);
|
||||
});
|
||||
return lst.split(',').map(s => parseInt(s, 10));
|
||||
}
|
||||
|
||||
exports.get_by_user_id = function (user_id) {
|
||||
|
@ -137,9 +135,7 @@ exports.huddle_string = function (message) {
|
|||
return;
|
||||
}
|
||||
|
||||
let user_ids = _.map(message.display_recipient, function (recip) {
|
||||
return recip.id;
|
||||
});
|
||||
let user_ids = message.display_recipient.map(recip => recip.id);
|
||||
|
||||
function is_huddle_recip(user_id) {
|
||||
return user_id &&
|
||||
|
@ -161,11 +157,9 @@ exports.huddle_string = function (message) {
|
|||
exports.user_ids_string_to_emails_string = function (user_ids_string) {
|
||||
const user_ids = split_to_ints(user_ids_string);
|
||||
|
||||
let emails = _.map(user_ids, function (user_id) {
|
||||
let emails = user_ids.map(user_id => {
|
||||
const person = people_by_user_id_dict.get(user_id);
|
||||
if (person) {
|
||||
return person.email;
|
||||
}
|
||||
return person && person.email;
|
||||
});
|
||||
|
||||
if (!_.all(emails)) {
|
||||
|
@ -173,9 +167,7 @@ exports.user_ids_string_to_emails_string = function (user_ids_string) {
|
|||
return;
|
||||
}
|
||||
|
||||
emails = _.map(emails, function (email) {
|
||||
return email.toLowerCase();
|
||||
});
|
||||
emails = emails.map(email => email.toLowerCase());
|
||||
|
||||
emails.sort();
|
||||
|
||||
|
@ -184,9 +176,7 @@ exports.user_ids_string_to_emails_string = function (user_ids_string) {
|
|||
|
||||
exports.user_ids_string_to_ids_array = function (user_ids_string) {
|
||||
const user_ids = user_ids_string.split(',');
|
||||
const ids = _.map(user_ids, function (id) {
|
||||
return Number(id);
|
||||
});
|
||||
const ids = user_ids.map(id => Number(id));
|
||||
return ids;
|
||||
};
|
||||
|
||||
|
@ -206,11 +196,9 @@ exports.reply_to_to_user_ids_string = function (emails_string) {
|
|||
// invalid data.
|
||||
const emails = emails_string.split(',');
|
||||
|
||||
let user_ids = _.map(emails, function (email) {
|
||||
let user_ids = emails.map(email => {
|
||||
const person = exports.get_by_email(email);
|
||||
if (person) {
|
||||
return person.user_id;
|
||||
}
|
||||
return person && person.user_id;
|
||||
});
|
||||
|
||||
if (!_.all(user_ids)) {
|
||||
|
@ -264,11 +252,9 @@ exports.emails_strings_to_user_ids_string = function (emails_string) {
|
|||
};
|
||||
|
||||
exports.email_list_to_user_ids_string = function (emails) {
|
||||
let user_ids = _.map(emails, function (email) {
|
||||
let user_ids = emails.map(email => {
|
||||
const person = exports.get_by_email(email);
|
||||
if (person) {
|
||||
return person.user_id;
|
||||
}
|
||||
return person && person.user_id;
|
||||
});
|
||||
|
||||
if (!_.all(user_ids)) {
|
||||
|
@ -282,11 +268,9 @@ exports.email_list_to_user_ids_string = function (emails) {
|
|||
};
|
||||
|
||||
exports.safe_full_names = function (user_ids) {
|
||||
let names = _.map(user_ids, function (user_id) {
|
||||
let names = user_ids.map(user_id => {
|
||||
const person = people_by_user_id_dict.get(user_id);
|
||||
if (person) {
|
||||
return person.full_name;
|
||||
}
|
||||
return person && person.full_name;
|
||||
});
|
||||
|
||||
names = _.filter(names);
|
||||
|
@ -309,7 +293,7 @@ exports.get_recipients = function (user_ids_string) {
|
|||
return exports.my_full_name();
|
||||
}
|
||||
|
||||
const names = _.map(other_ids, exports.get_full_name).sort();
|
||||
const names = other_ids.map(exports.get_full_name).sort();
|
||||
return names.join(', ');
|
||||
};
|
||||
|
||||
|
@ -330,7 +314,7 @@ exports.pm_reply_to = function (message) {
|
|||
return;
|
||||
}
|
||||
|
||||
const emails = _.map(user_ids, function (user_id) {
|
||||
const emails = user_ids.map(user_id => {
|
||||
const person = people_by_user_id_dict.get(user_id);
|
||||
if (!person) {
|
||||
blueslip.error('Unknown user id in message: ' + user_id);
|
||||
|
@ -386,9 +370,7 @@ exports.all_user_ids_in_pm = function (message) {
|
|||
return;
|
||||
}
|
||||
|
||||
let user_ids = _.map(message.display_recipient, function (recip) {
|
||||
return recip.id;
|
||||
});
|
||||
let user_ids = message.display_recipient.map(recip => recip.id);
|
||||
|
||||
user_ids = sort_numerically(user_ids);
|
||||
return user_ids;
|
||||
|
@ -404,9 +386,7 @@ exports.pm_with_user_ids = function (message) {
|
|||
return;
|
||||
}
|
||||
|
||||
const user_ids = _.map(message.display_recipient, function (recip) {
|
||||
return recip.id;
|
||||
});
|
||||
const user_ids = message.display_recipient.map(recip => recip.id);
|
||||
|
||||
return sorted_other_user_ids(user_ids);
|
||||
};
|
||||
|
@ -421,9 +401,7 @@ exports.group_pm_with_user_ids = function (message) {
|
|||
return;
|
||||
}
|
||||
|
||||
const user_ids = _.map(message.display_recipient, function (recip) {
|
||||
return recip.id;
|
||||
});
|
||||
const user_ids = message.display_recipient.map(recip => recip.id);
|
||||
const is_user_present = _.some(user_ids, function (user_id) {
|
||||
return exports.is_my_user_id(user_id);
|
||||
});
|
||||
|
@ -488,9 +466,7 @@ exports.update_email_in_reply_to = function (reply_to, user_id, new_email) {
|
|||
// and we don't warn on any errors.
|
||||
let emails = reply_to.split(',');
|
||||
|
||||
const persons = _.map(emails, function (email) {
|
||||
return people_dict.get(email.trim());
|
||||
});
|
||||
const persons = emails.map(email => people_dict.get(email.trim()));
|
||||
|
||||
if (!_.all(persons)) {
|
||||
return reply_to;
|
||||
|
@ -504,7 +480,7 @@ exports.update_email_in_reply_to = function (reply_to, user_id, new_email) {
|
|||
return reply_to;
|
||||
}
|
||||
|
||||
emails = _.map(persons, function (person) {
|
||||
emails = persons.map(person => {
|
||||
if (person.user_id === user_id) {
|
||||
return new_email;
|
||||
}
|
||||
|
@ -516,10 +492,8 @@ exports.update_email_in_reply_to = function (reply_to, user_id, new_email) {
|
|||
|
||||
exports.pm_with_operand_ids = function (operand) {
|
||||
let emails = operand.split(',');
|
||||
emails = _.map(emails, function (email) { return email.trim(); });
|
||||
let persons = _.map(emails, function (email) {
|
||||
return people_dict.get(email);
|
||||
});
|
||||
emails = emails.map(email => email.trim());
|
||||
let persons = emails.map(email => people_dict.get(email));
|
||||
|
||||
// If your email is included in a PM group with other people, just ignore it
|
||||
if (persons.length > 1) {
|
||||
|
@ -530,9 +504,7 @@ exports.pm_with_operand_ids = function (operand) {
|
|||
return;
|
||||
}
|
||||
|
||||
let user_ids = _.map(persons, function (person) {
|
||||
return person.user_id;
|
||||
});
|
||||
let user_ids = persons.map(person => person.user_id);
|
||||
|
||||
user_ids = sort_numerically(user_ids);
|
||||
|
||||
|
@ -788,9 +760,7 @@ exports.get_message_people = function () {
|
|||
semantics
|
||||
*/
|
||||
const message_people = _.compact(
|
||||
_.map(message_store.user_ids(), (user_id) => {
|
||||
return people_by_user_id_dict.get(user_id);
|
||||
})
|
||||
message_store.user_ids().map(user_id => people_by_user_id_dict.get(user_id))
|
||||
);
|
||||
|
||||
return message_people;
|
||||
|
@ -835,7 +805,7 @@ exports.build_person_matcher = function (query) {
|
|||
query = query.trim();
|
||||
|
||||
const termlets = query.toLowerCase().split(/\s+/);
|
||||
const termlet_matchers = _.map(termlets, exports.build_termlet_matcher);
|
||||
const termlet_matchers = termlets.map(exports.build_termlet_matcher);
|
||||
|
||||
return function (user) {
|
||||
const email = user.email.toLowerCase();
|
||||
|
@ -855,9 +825,7 @@ exports.filter_people_by_search_terms = function (users, search_terms) {
|
|||
|
||||
// Build our matchers outside the loop to avoid some
|
||||
// search overhead that is not user-specific.
|
||||
const matchers = _.map(search_terms, function (search_term) {
|
||||
return exports.build_person_matcher(search_term);
|
||||
});
|
||||
const matchers = search_terms.map(search_term => exports.build_person_matcher(search_term));
|
||||
|
||||
// Loop through users and populate filtered_users only
|
||||
// if they include search_terms
|
||||
|
|
|
@ -26,7 +26,7 @@ exports.pm_ul = (convos) => {
|
|||
];
|
||||
return vdom.ul({
|
||||
attrs: attrs,
|
||||
keyed_nodes: _.map(convos, exports.keyed_pm_li),
|
||||
keyed_nodes: convos.map(exports.keyed_pm_li),
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -45,11 +45,9 @@ function format_as_suggestion(terms) {
|
|||
}
|
||||
|
||||
function compare_by_huddle(huddle) {
|
||||
huddle = _.map(huddle.slice(0, -1), function (person) {
|
||||
huddle = huddle.slice(0, -1).map(person => {
|
||||
person = people.get_by_email(person);
|
||||
if (person) {
|
||||
return person.user_id;
|
||||
}
|
||||
return person && person.user_id;
|
||||
});
|
||||
|
||||
// Construct dict for all huddles, so we can lookup each's recency
|
||||
|
@ -99,7 +97,7 @@ function get_stream_suggestions(last, operators) {
|
|||
const regex = typeahead_helper.build_highlight_regex(query);
|
||||
const hilite = typeahead_helper.highlight_with_escaping_and_regex;
|
||||
|
||||
const objs = _.map(streams, function (stream) {
|
||||
const objs = streams.map(stream => {
|
||||
const prefix = 'stream';
|
||||
const highlighted_stream = hilite(regex, stream);
|
||||
const verb = last.negated ? 'exclude ' : '';
|
||||
|
@ -160,7 +158,7 @@ function get_group_suggestions(last, operators) {
|
|||
|
||||
const highlight_person = make_person_highlighter(last_part);
|
||||
|
||||
const suggestions = _.map(persons, function (person) {
|
||||
const suggestions = persons.map(person => {
|
||||
const term = {
|
||||
operator: 'pm-with',
|
||||
operand: all_but_last_part + ',' + person.email,
|
||||
|
@ -240,7 +238,7 @@ function get_person_suggestions(people_getter, last, operators, autocomplete_ope
|
|||
|
||||
const highlight_person = make_person_highlighter(query);
|
||||
|
||||
const objs = _.map(persons, function (person) {
|
||||
const objs = persons.map(person => {
|
||||
const name = highlight_person(person);
|
||||
const description = prefix + ' ' + name;
|
||||
const terms = [{
|
||||
|
@ -363,7 +361,7 @@ function get_topic_suggestions(last, operators) {
|
|||
// care about case.
|
||||
topics.sort();
|
||||
|
||||
return _.map(topics, function (topic) {
|
||||
return topics.map(topic => {
|
||||
const topic_term = {operator: 'topic', operand: topic, negated: negated};
|
||||
const operators = suggest_operators.concat([topic_term]);
|
||||
return format_as_suggestion(operators);
|
||||
|
@ -394,13 +392,11 @@ function get_special_filter_suggestions(last, operators, suggestions) {
|
|||
// Negating suggestions on is_search_operand_negated is required for
|
||||
// suggesting negated operators.
|
||||
if (last.negated || is_search_operand_negated) {
|
||||
suggestions = _.map(suggestions, function (suggestion) {
|
||||
return {
|
||||
suggestions = suggestions.map(suggestion => ({
|
||||
search_string: '-' + suggestion.search_string,
|
||||
description: 'exclude ' + suggestion.description,
|
||||
invalid: suggestion.invalid,
|
||||
};
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
const last_string = Filter.unparse([last]).toLowerCase();
|
||||
|
@ -583,7 +579,7 @@ function get_operator_suggestions(last) {
|
|||
return common.phrase_match(last_operand, choice);
|
||||
});
|
||||
|
||||
return _.map(choices, function (choice) {
|
||||
return choices.map(choice => {
|
||||
const op = [{operator: choice, operand: '', negated: negated}];
|
||||
return format_as_suggestion(op);
|
||||
});
|
||||
|
@ -848,9 +844,7 @@ exports.finalize_search_result = function (result) {
|
|||
lookup_table[obj.search_string] = obj;
|
||||
}
|
||||
|
||||
const strings = _.map(result, function (obj) {
|
||||
return obj.search_string;
|
||||
});
|
||||
const strings = result.map(obj => obj.search_string);
|
||||
return {
|
||||
strings: strings,
|
||||
lookup_table: lookup_table,
|
||||
|
|
|
@ -373,9 +373,9 @@ exports.populate_realm_domains = function (realm_domains) {
|
|||
return;
|
||||
}
|
||||
|
||||
const domains_list = _.map(realm_domains, function (realm_domain) {
|
||||
return realm_domain.allow_subdomains ? "*." + realm_domain.domain : realm_domain.domain;
|
||||
});
|
||||
const domains_list = realm_domains.map(
|
||||
realm_domain => realm_domain.allow_subdomains ? "*." + realm_domain.domain : realm_domain.domain
|
||||
);
|
||||
let domains = domains_list.join(', ');
|
||||
if (domains.length === 0) {
|
||||
domains = i18n.t("None");
|
||||
|
|
|
@ -101,11 +101,9 @@ function ajaxSubscribeForCreation(stream_name, description, user_ids, invite_onl
|
|||
stream_post_policy, announce, history_public_to_subscribers) {
|
||||
// TODO: We can eliminate the user_ids -> principals conversion
|
||||
// once we upgrade the backend to accept user_ids.
|
||||
const persons = _.compact(_.map(user_ids, (user_id) => {
|
||||
return people.get_by_user_id(user_id);
|
||||
}));
|
||||
const persons = _.compact(user_ids.map(user_id => people.get_by_user_id(user_id)));
|
||||
|
||||
const principals = _.map(persons, (person) => person.email);
|
||||
const principals = persons.map(person => person.email);
|
||||
|
||||
// Subscribe yourself and possible other people to a new stream.
|
||||
return channel.post({
|
||||
|
|
|
@ -344,8 +344,8 @@ exports.get_invite_stream_data = function () {
|
|||
default_stream: exports.get_default_status(sub.name),
|
||||
};
|
||||
};
|
||||
const invite_stream_data = _.map(exports.subscribed_subs(), filter_stream_data);
|
||||
const default_stream_data = _.map(page_params.realm_default_streams, filter_stream_data);
|
||||
const invite_stream_data = exports.subscribed_subs().map(filter_stream_data);
|
||||
const default_stream_data = page_params.realm_default_streams.map(filter_stream_data);
|
||||
|
||||
// Since, union doesn't work on array of objects we are using filter
|
||||
const is_included = {};
|
||||
|
@ -462,9 +462,7 @@ exports.home_view_stream_names = function () {
|
|||
const home_view_subs = _.filter(exports.subscribed_subs(), function (sub) {
|
||||
return !sub.is_muted;
|
||||
});
|
||||
return _.map(home_view_subs, function (sub) {
|
||||
return sub.name;
|
||||
});
|
||||
return home_view_subs.map(sub => sub.name);
|
||||
};
|
||||
|
||||
exports.canonicalized_name = function (stream_name) {
|
||||
|
@ -571,7 +569,7 @@ exports.set_realm_default_streams = function (realm_default_streams) {
|
|||
};
|
||||
|
||||
exports.get_default_stream_names = function () {
|
||||
const streams = _.map(Array.from(default_stream_ids), exports.get_sub_by_id);
|
||||
const streams = Array.from(default_stream_ids).map(exports.get_sub_by_id);
|
||||
const default_stream_names = _.pluck(streams, 'name');
|
||||
return default_stream_names;
|
||||
};
|
||||
|
|
|
@ -15,9 +15,7 @@ function filter_streams_by_search(streams, search_term) {
|
|||
}
|
||||
|
||||
let search_terms = search_term.toLowerCase().split(",");
|
||||
search_terms = _.map(search_terms, function (s) {
|
||||
return s.trim();
|
||||
});
|
||||
search_terms = search_terms.map(s => s.trim());
|
||||
|
||||
const filtered_streams = _.filter(streams, function (stream) {
|
||||
return _.any(search_terms, function (search_term) {
|
||||
|
|
|
@ -15,12 +15,10 @@ exports.get_message_events = function (message) {
|
|||
return parseInt(m1.id, 10) - parseInt(m2.id, 10);
|
||||
});
|
||||
|
||||
const events = _.map(message.submessages, function (obj) {
|
||||
return {
|
||||
const events = message.submessages.map(obj => ({
|
||||
sender_id: obj.sender_id,
|
||||
data: JSON.parse(obj.content),
|
||||
};
|
||||
});
|
||||
}));
|
||||
|
||||
return events;
|
||||
};
|
||||
|
|
|
@ -61,7 +61,7 @@ function make_tab_data() {
|
|||
|
||||
if (filter.has_operator("pm-with")) {
|
||||
const emails = filter.operands("pm-with")[0].split(',');
|
||||
const names = _.map(emails, function (email) {
|
||||
const names = emails.map(email => {
|
||||
if (!people.get_by_email(email)) {
|
||||
return email;
|
||||
}
|
||||
|
|
|
@ -154,9 +154,7 @@ exports.topic_history = function (stream_id) {
|
|||
return b.message_id - a.message_id;
|
||||
});
|
||||
|
||||
const names = _.map(recents, function (obj) {
|
||||
return obj.pretty_name;
|
||||
});
|
||||
const names = recents.map(obj => obj.pretty_name);
|
||||
|
||||
return names;
|
||||
};
|
||||
|
|
|
@ -136,8 +136,7 @@ exports.widget = function (parent_elem, my_stream_id) {
|
|||
['class', 'topic-list'],
|
||||
];
|
||||
|
||||
const nodes = _.map(
|
||||
list_info.items, exports.keyed_topic_li);
|
||||
const nodes = list_info.items.map(exports.keyed_topic_li);
|
||||
|
||||
if (spinner) {
|
||||
nodes.push(exports.spinner_li());
|
||||
|
|
|
@ -283,7 +283,7 @@ exports.unread_topic_counter = (function () {
|
|||
return topic_dict.has(topic_name);
|
||||
});
|
||||
|
||||
const result = _.map(topic_names, function (topic_name) {
|
||||
const result = topic_names.map(topic_name => {
|
||||
const msgs = per_stream_bucketer.get_bucket(topic_name);
|
||||
|
||||
return {
|
||||
|
|
|
@ -107,8 +107,8 @@ exports.normalize_recipients = function (recipients) {
|
|||
// Converts a string listing emails of message recipients
|
||||
// into a canonical formatting: emails sorted ASCIIbetically
|
||||
// with exactly one comma and no spaces between each.
|
||||
recipients = _.map(recipients.split(','), function (s) { return s.trim(); });
|
||||
recipients = _.map(recipients, function (s) { return s.toLowerCase(); });
|
||||
recipients = recipients.split(',').map(s => s.trim());
|
||||
recipients = recipients.map(s => s.toLowerCase());
|
||||
recipients = _.filter(recipients, function (s) { return s.length > 0; });
|
||||
recipients.sort();
|
||||
return recipients.join(',');
|
||||
|
@ -249,7 +249,7 @@ function to_int(s) {
|
|||
exports.sorted_ids = function (ids) {
|
||||
// This mapping makes sure we are using ints, and
|
||||
// it also makes sure we don't mutate the list.
|
||||
let id_list = _.map(ids, to_int);
|
||||
let id_list = ids.map(to_int);
|
||||
id_list.sort(function (a, b) {
|
||||
return a - b;
|
||||
});
|
||||
|
|
|
@ -39,9 +39,7 @@ exports.render_tag = (tag) => {
|
|||
*/
|
||||
const opts = tag.opts;
|
||||
const tag_name = tag.tag_name;
|
||||
const attr_str = _.map(opts.attrs, (attr) => {
|
||||
return ' ' + attr[0] + '="' + util.escape_html(attr[1]) + '"';
|
||||
}).join('');
|
||||
const attr_str = opts.attrs.map(attr => ' ' + attr[0] + '="' + util.escape_html(attr[1]) + '"').join('');
|
||||
|
||||
const start_tag = '<' + tag_name + attr_str + '>';
|
||||
const end_tag = '</' + tag_name + '>';
|
||||
|
@ -51,9 +49,7 @@ exports.render_tag = (tag) => {
|
|||
return;
|
||||
}
|
||||
|
||||
const innards = _.map(opts.keyed_nodes, (node) => {
|
||||
return node.render();
|
||||
}).join('\n');
|
||||
const innards = opts.keyed_nodes.map(node => node.render()).join('\n');
|
||||
return start_tag + '\n' + innards + '\n' + end_tag;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue