Replace $.each with _.each

In a few cases the $.each was doing something imperatively that was
terser and easier to understand by using a different Underscore method,
so a few of these I rewrote.

Some code was using the fact that jQuery sets `this` in the callback to
be the item; I rewrote those to use an explicit parameter.

Some code was using $(some selector).each(callback). I converted these
to _.each($(some selector), callback).

One function, ui.process_condensing, was written to be a jQuery $.each
callback despite being in a totally different module from code using it.
I noticed this and updated the function's args.

(imported from commit bf5922a35f257c168cc09ec1d077415d6ef19a03)
This commit is contained in:
Scott Feeney 2013-07-29 18:35:44 -04:00
parent 5842d5c335
commit 8703134a23
24 changed files with 113 additions and 143 deletions

View File

@ -113,7 +113,7 @@ function focus_ping() {
}
// Ping returns the active peer list
$.each(data.presences, function (this_email, presence) {
_.each(data.presences, function (presence, this_email) {
if (page_params.email !== this_email) {
user_info[this_email] = status_from_timestamp(data.server_timestamp, presence);
}
@ -152,7 +152,7 @@ exports.initialize = function () {
// This rerenders the user sidebar at the end, which can be slow if done too
// often, so try to avoid calling this repeatedly.
exports.set_user_statuses = function (users, server_time) {
$.each(users, function (email, presence) {
_.each(users, function (presence, email) {
if (email === page_params.email) {
return;
}

View File

@ -174,7 +174,7 @@ exports.wrap_function = function blueslip_wrap_function(func) {
}
$.ajaxPrefilter(function (options) {
$.each(['success', 'error', 'complete'], function (idx, cb_name) {
_.each(['success', 'error', 'complete'], function (cb_name) {
if (options[cb_name] !== undefined) {
options[cb_name] = exports.wrap_function(options[cb_name]);
}

View File

@ -28,14 +28,14 @@ function print_elapsed_time(name, fun) {
/* An IterationProfiler is used for profiling parts of looping
* constructs (like a for loop or $.each). You mark sections of the
* constructs (like a for loop or _.each). You mark sections of the
* iteration body and the IterationProfiler will sum the costs of those
* sections over all iterations.
*
* Example:
*
* var ip = new IterationProfiler();
* $.each(myarray, function (idx, elem) {
* _.each(myarray, function (elem) {
* ip.iteration_start();
*
* cheap_op(elem);

File diff suppressed because one or more lines are too long

View File

@ -44,7 +44,7 @@ exports.operators_to_hash = function (operators) {
if (operators !== undefined) {
hash = '#narrow';
$.each(operators, function (idx, elem) {
_.each(operators, function (elem) {
hash += '/' + hashchange.encodeHashComponent(elem[0])
+ '/' + hashchange.encodeHashComponent(elem[1]);
});

View File

@ -133,7 +133,7 @@ function is_local_part(value, element) {
function get_invitee_emails() {
var emails = [];
$.each($('.invite_row > input'), function (idx, elem) {
_.each($('.invite_row > input'), function (elem) {
var email = $(elem).val();
if (email === '') {
@ -210,4 +210,4 @@ $(document).ready(function () {
return exports;
}());
}());

View File

@ -8,7 +8,7 @@ function update_subscription_checkboxes() {
// checkboxes are saved from invocation to invocation (which is
// nice if I want to invite a bunch of people at once)
var streams = [];
$.each(subs.subscribed_streams(), function (index, value) {
_.each(subs.subscribed_streams(), function (value) {
streams.push({name: value, invite_only: subs.get_invite_only(value)});
});
$('#streams_to_add').html(templates.render('invite_subscription', {streams: streams}));
@ -70,7 +70,7 @@ exports.initialize = function () {
} else {
// Some users were not invited.
var error_list = $('<ul>');
$.each(arr.errors, function (index, value) {
_.each(arr.errors, function (value) {
error_list.append($('<li>').text(value.join(': ')));
});

View File

@ -25,7 +25,7 @@ $(function () {
beforeSubmit: function (arr, form, options) {
$(".alert-hidden").hide();
var has_email = false;
$.each(arr, function (idx, elt) {
_.each(arr, function (elt) {
if (elt.name === 'email' && elt.value.length) {
has_email = true;
}

View File

@ -105,7 +105,7 @@ exports.maybe_show_edit = function (row, id) {
};
$(document).on('narrow_deactivated.zulip', function (event) {
$.each(currently_editing_messages, function (idx, elem) {
_.each(currently_editing_messages, function (elem, idx) {
if (current_msg_list.get(idx) !== undefined) {
var row = rows.get(idx, current_msg_list.table_name);
current_msg_list.show_edit_message(row, elem);

View File

@ -175,7 +175,7 @@ MessageList.prototype = {
var id_set = {};
$.each(msg_ids, function (idx, msg_id) {
_.each(msg_ids, function (msg_id) {
id_set[msg_id] = true;
});
@ -319,7 +319,7 @@ MessageList.prototype = {
var top_group = this._message_groups[0];
var top_messages = [];
$.each(top_group, function (index, id) {
_.each(top_group, function (id) {
rows.get(id, table_name).remove();
// Remove any date row headers for these messages
$('.date_row[data-zid=' + id + ']').remove();
@ -334,7 +334,7 @@ MessageList.prototype = {
prev = this.get(last_message_id);
}
$.each(messages, function (index, message) {
_.each(messages, function (message) {
message.include_recipient = false;
message.include_bookend = false;
message.include_footer = false;
@ -423,7 +423,7 @@ MessageList.prototype = {
use_match_properties: this.filter.is_search()
}));
$.each(rendered_elems, function (index, elem) {
_.each(rendered_elems, function (elem) {
var row = $(elem);
if (! row.hasClass('message_row')) {
return;
@ -487,7 +487,7 @@ MessageList.prototype = {
}});
}
$.each(rendered_elems, function (idx, elem) {
_.each(rendered_elems, function (elem) {
var row = $(elem);
if (! row.hasClass('message_row')) {
return;
@ -498,7 +498,7 @@ MessageList.prototype = {
// Must happen after the elements are inserted into the document for
// getBoundingClientRect to work.
$.each(rendered_elems, ui.process_condensing);
_.each(rendered_elems, ui.process_condensing);
// Must happen after anything that changes the height of messages has
// taken effect.
@ -541,11 +541,11 @@ MessageList.prototype = {
}
var new_messages_height = 0;
$.each(rendered_elems, function () {
_.each(rendered_elems, function (elem) {
// Sometimes there are non-DOM elements in rendered_elems; only
// try to get the heights of actual trs.
if ($(this).is("tr")) {
new_messages_height += $(this).height();
if ($(elem).is("tr")) {
new_messages_height += $(elem).height();
}
});

View File

@ -34,57 +34,35 @@ Filter.prototype = {
},
public_operators: function Filter_public_operators() {
var safe_to_return;
safe_to_return = [];
$.each(this._operators, function (index, value) {
var safe_to_return = _.filter(this._operators, function (value) {
// Currently just filter out the "in" keyword.
if (value[0] !== "in") {
safe_to_return.push(value);
}
return value[0] !== 'in';
});
if (safe_to_return.length !== 0) {
if (safe_to_return.length !== 0)
return safe_to_return;
}
},
operands: function Filter_get_operands(operator) {
var result = [];
$.each(this._operators, function (idx, elem) {
if (elem[0] === operator) {
result.push(elem[1]);
}
});
return result;
return _.chain(this._operators)
.filter(function (elem) { return elem[0] === operator; })
.map(function (elem) { return elem[1]; })
.value();
},
has_operand: function Filter_has_operand(operator, operand) {
var result = false;
$.each(this._operators, function (idx, elem) {
if (elem[0] === operator && elem[1] === operand) {
result = true;
}
return _.some(this._operators, function (elem) {
return elem[0] === operator && elem[1] === operand;
});
return result;
},
has_operator: function Filter_has_operand(operator) {
var result = false;
$.each(this._operators, function (idx, elem) {
if (elem[0] === operator) {
result = true;
}
has_operator: function Filter_has_operator(operator) {
return _.some(this._operators, function (elem) {
return elem[0] === operator;
});
return result;
},
is_search: function Filter_is_search() {
var retval = false;
$.each(this._operators, function (idx, elem) {
if (elem[0] === "search") {
retval = true;
return false;
}});
return retval;
return this.has_operator('search');
},
can_apply_locally: function Filter_can_apply_locally() {
@ -248,16 +226,15 @@ function decodeOperand(encoded) {
might need to support multiple operators of the same type.
*/
exports.unparse = function (operators) {
var parts = [];
$.each(operators, function (index, elem) {
var parts = _.map(operators, function (elem) {
var operator = elem[0];
if (operator === 'search') {
// Search terms are the catch-all case.
// All tokens that don't start with a known operator and
// a colon are glued together to form a search term.
parts.push(elem[1]);
return elem[1];
} else {
parts.push(elem[0] + ':' + encodeOperand(elem[1].toString().toLowerCase()));
return elem[0] + ':' + encodeOperand(elem[1].toString().toLowerCase());
}
});
return parts.join(' ');
@ -272,7 +249,7 @@ exports.search_string = function () {
function collect_single(operators) {
var seen = {};
var result = {};
$.each(operators, function (index, elem) {
_.each(operators, function (elem) {
var key = elem[0];
if (seen.hasOwnProperty(key)) {
delete result[key];
@ -295,7 +272,7 @@ exports.set_compose_defaults = function (opts) {
// Set the stream, subject, and/or PM recipient if they are
// uniquely specified in the narrow view.
$.each(['stream', 'topic'], function (idx, key) {
_.each(['stream', 'topic'], function (key) {
if (single[key] !== undefined)
opts[key] = single[key];
});
@ -312,7 +289,7 @@ exports.parse = function (str) {
if (matches === null) {
return operators;
}
$.each(matches, function (idx, token) {
_.each(matches, function (token) {
var parts, operator;
if (token.length === 0)
return;
@ -405,7 +382,7 @@ exports.activate = function (operators, opts) {
if (! narrowed_msg_list.empty()) {
if (opts.select_first_unread) {
then_select_id = narrowed_msg_list.last().id;
$.each(narrowed_msg_list.all(), function (idx, msg) {
_.each(narrowed_msg_list.all(), function (msg) {
if (unread.message_unread(msg)) {
then_select_id = msg.id;
return false;
@ -465,7 +442,7 @@ exports.activate = function (operators, opts) {
// above us could change size -- which is problematic, because it
// could cause us to lose our position. But doing this here, right
// after showing the table, seems to cause us to win the race.
$("tr.message_row").each(ui.process_condensing);
_.each($("tr.message_row"), ui.process_condensing);
reset_load_more_status();
if (! defer_selecting_closest) {

View File

@ -27,7 +27,7 @@ exports.initialize = function () {
$(window).focus(function () {
window_has_focus = true;
$.each(notice_memory, function (index, notice_mem_entry) {
_.each(notice_memory, function (notice_mem_entry) {
notice_mem_entry.obj.cancel();
});
@ -276,7 +276,7 @@ function message_is_notifiable(message) {
}
exports.received_messages = function (messages) {
$.each(messages, function (index, message) {
_.each(messages, function (message) {
if (!message_is_notifiable(message)) return;
if (!unread.message_unread(message)) return;

View File

@ -12,9 +12,8 @@ var step_info = {sent_stream_message: {"user_message": "Send a stream message"},
var onboarding = false;
function update_onboarding_steps() {
var step_statuses = [];
$.each(steps, function (idx, step) {
step_statuses.push([step, step_info[step].status]);
var step_statuses = _.map(steps, function (step) {
return [step, step_info[step].status];
});
$.ajax({
@ -50,7 +49,7 @@ function update_checklist_ui(step) {
}
exports.set_step_info = function (steps) {
$.each(steps, function (idx, step) {
_.each(steps, function (step) {
var step_name = step[0];
var status = step[1];
step_info[step_name].status = status;
@ -121,7 +120,7 @@ function set_up_checklist() {
return;
}
$.each(steps, function (idx, step) {
_.each(steps, function (step) {
var entry = $('<div>');
if (step_info[step].status) {
entry.append($("<i class='icon-vector-check'>"));

View File

@ -58,7 +58,7 @@ $(function () {
fragment = fragment.replace(/^reload:/, "");
var keyvals = fragment.split("+");
var vars = {};
$.each(keyvals, function (idx, str) {
_.each(keyvals, function (str) {
var pair = str.split("=");
vars[pair[0]] = decodeURIComponent(pair[1]);
});

View File

@ -461,7 +461,7 @@ exports.get_suggestions = function (query) {
// back to our objects, and we also filter duplicates here.
search_object = {};
var final_result = [];
$.each(result, function (idx, obj) {
_.each(result, function (obj) {
if (!search_object[obj.search_string]) {
search_object[obj.search_string] = obj;
final_result.push(obj);

View File

@ -28,7 +28,7 @@ $(function () {
success: function (data) {
$('#bot_table_error').hide();
$.each(data.bots, function (idx, elem) {
_.each(data.bots, function (elem) {
add_bot_row(elem.full_name, elem.username, elem.avatar_url, elem.api_key);
});
},

View File

@ -38,7 +38,7 @@ exports.sort_narrow_list = function () {
parent.empty();
var elems = [];
$.each(streams, function (i, stream) {
_.each(streams, function (stream) {
var li = $(subs.get(stream).sidebar_li);
if (sort_recent) {
if (recent_subjects[stream] === undefined) {
@ -53,16 +53,11 @@ exports.sort_narrow_list = function () {
};
function iterate_to_find(selector, name_to_find, context) {
var retval = $();
$(selector, context).each(function (idx, elem) {
var jelem = $(elem);
var elem_name = jelem.attr('data-name');
if (elem_name.toLowerCase() === name_to_find.toLowerCase()) {
retval = jelem;
return false;
}
var lowercase_name = name_to_find.toLowerCase();
var found = _.find($(selector, context), function (elem) {
return $(elem).attr('data-name') === lowercase_name;
});
return retval;
return found ? $(found) : $();
}
// TODO: Now that the unread count functions support the user sidebar
@ -235,19 +230,19 @@ exports.update_dom_with_unread_counts = function (counts) {
// Our job is to update some DOM elements.
// counts.stream_count maps streams to counts
$.each(counts.stream_count, function (stream, count) {
_.each(counts.stream_count, function (count, stream) {
exports.set_count("stream", stream, count);
});
// counts.subject_count maps streams to hashes of subjects to counts
$.each(counts.subject_count, function (stream, subject_hash) {
$.each(subject_hash, function (subject, count) {
_.each(counts.subject_count, function (subject_hash, stream) {
_.each(subject_hash, function (count, subject) {
exports.set_subject_count(stream, subject, count);
});
});
// counts.pm_count maps people to counts
$.each(counts.pm_count, function (person, count) {
_.each(counts.pm_count, function (count, person) {
exports.set_count("private", person, count);
});

View File

@ -63,21 +63,16 @@ function mark_color_used(color) {
}
exports.subscribed_streams = function () {
// TODO: Object.keys() compatibility
var list = [];
$.each(Object.keys(stream_info), function (idx, key) {
var sub = stream_info[key];
if (sub.subscribed) {
list.push(sub.name);
}
});
list.sort();
return list;
return _.chain(stream_info)
.values()
.filter(function (sub) { return sub.subscribed; })
.map(function (sub) { return sub.name; })
.value();
};
exports.maybe_toggle_all_messages = function () {
var show_all_messages = false;
$.each(stream_info, function (idx, stream) {
_.each(stream_info, function (stream) {
if (!stream.in_home_view) {
show_all_messages = true;
return false;
@ -108,10 +103,12 @@ function update_table_stream_color(table, stream_name, color) {
.addClass(color_class);
}
$.each($("#floating_recipient_bar").add(table).find(".stream_label"), function () {
if ($(this).text() === stream_name) {
fixup($(this).parent("td").parent("tr").prev("tr").nextUntil(".bookend_tr")
.children(".messagebox_colorblock,.message_header_colorblock"));
var stream_labels = $("#floating_recipient_bar").add(table).find(".stream_label");
_.each(stream_labels, function (label) {
if ($(label).text() === stream_name) {
fixup($(label).parent("td").parent("tr").prev("tr")
.nextUntil(".bookend_tr")
.children(".messagebox_colorblock,.message_header_colorblock"));
}
});
}
@ -586,7 +583,7 @@ exports.setup_page = function () {
/* arguments are [ "success", statusText, jqXHR ] */
if (stream_data.length > 2 && stream_data[2]) {
var stream_response = JSON.parse(stream_data[2].responseText);
$.each(stream_response.streams, function (idx, stream) {
_.each(stream_response.streams, function (stream) {
all_streams.push(stream.name);
});
}
@ -597,8 +594,8 @@ exports.setup_page = function () {
// All streams won't contain invite-only streams,
// or anything at all if should_list_all_streams() is false
$.each(our_subs, function (idx, stream) {
if (all_streams.indexOf(stream.name) === -1) {
_.each(our_subs, function (stream) {
if (_.indexOf(all_streams, stream.name) === -1) {
all_streams.push(stream.name);
}
});
@ -776,7 +773,7 @@ function people_cmp(person1, person2) {
function show_new_stream_modal() {
var people_minus_you_and_maybe_humbuggers = [];
$.each(page_params.people_list, function (idx, person) {
_.each(page_params.people_list, function (person) {
if (person.email !== page_params.email &&
(page_params.domain === "zulip.com" ||
person.email.split('@')[1] !== "zulip.com"
@ -820,10 +817,12 @@ $(function () {
$("#stream_creation_form").on("submit", function (e) {
e.preventDefault();
var stream = $.trim($("#create_stream_name").val());
var principals = [];
$("#stream_creation_form input:checkbox[name=user]:checked").each(function () {
principals.push($(this).val());
});
var principals = _.map(
$("#stream_creation_form input:checkbox[name=user]:checked"),
function (elem) {
return $(elem).val();
}
);
// You are always subscribed to streams you create.
principals.push(page_params.email);
ajaxSubscribeForCreation(stream,
@ -963,7 +962,7 @@ $(function () {
}
return format_member_list_elem(people_dict[elem].full_name, elem);
});
$.each(subscribers.sort().reverse(), function (idx, elem) {
_.each(subscribers.sort().reverse(), function (elem) {
// add_to_member_list *prepends* the element,
// so we need to sort in reverse order for it to
// appear in alphabetical order.

View File

@ -81,7 +81,7 @@ exports.update_timestamps = function () {
var to_process = update_list;
update_list = [];
$.each(to_process, function (idx, elem) {
_.each(to_process, function (elem) {
var id = elem[0];
var element = document.getElementById(id);
// The element might not exist any more (because it

View File

@ -128,7 +128,7 @@ var fake_messages = [
function disable_event_handlers() {
$('body').css({'overflow':'hidden'}); // prevents scrolling the feed
$.each(["keydown", "keyup", "keypress", "scroll"], function (idx, event_name) {
_.each(["keydown", "keyup", "keypress", "scroll"], function (event_name) {
var existing_events = $(document).data("events")[event_name];
if (existing_events === undefined) {
existing_events = [];
@ -140,7 +140,7 @@ function disable_event_handlers() {
function enable_event_handlers() {
$('body').css({'overflow':'auto'}); // enables scrolling the feed
$.each(["keydown", "keyup", "keypress", "scroll"], function (idx, event_name) {
_.each(["keydown", "keyup", "keypress", "scroll"], function (event_name) {
$(document).data("events")[event_name] = event_handlers[event_name];
});
}
@ -266,7 +266,7 @@ function home() {
var x = spotlight_message.offset().left;
var y = spotlight_message.offset().top;
var height = 0;
$.each(messages_in_viewport(), function (idx, row) {
_.each(messages_in_viewport(), function (row) {
height += $(row).height();
});

View File

@ -19,7 +19,7 @@ exports.highlight_with_escaping = function (query, item) {
// to know the case of the content we're replacing (you can't just use a bolded
// version of 'query')
var result = "";
$.each(pieces, function (idx, piece) {
_.each(pieces, function (piece) {
if (piece.match(regex)) {
result += "<strong>" + Handlebars.Utils.escapeExpression(piece) + "</strong>";
} else {
@ -32,7 +32,7 @@ exports.highlight_with_escaping = function (query, item) {
exports.highlight_with_escaping_and_regex = function (regex, item) {
var pieces = item.split(regex);
var result = "";
$.each(pieces, function (idx, piece) {
_.each(pieces, function (piece) {
if (piece.match(regex)) {
result += "<strong>" + Handlebars.Utils.escapeExpression(piece) + "</strong>";
} else {
@ -84,13 +84,13 @@ exports.known_to_typeahead = function (recipient_data) {
};
exports.update_all_recipients = function (recipients) {
$.each(recipients, function (idx, recipient_data) {
_.each(recipients, function (recipient_data) {
add_to_known_recipients(recipient_data, false);
});
};
exports.update_your_recipients = function (recipients) {
$.each(recipients, function (idx, recipient_data) {
_.each(recipients, function (recipient_data) {
if (recipient_data.email !== page_params.email) {
add_to_known_recipients(recipient_data, true);
}
@ -98,7 +98,7 @@ exports.update_your_recipients = function (recipients) {
};
exports.remove_recipient = function (recipients) {
$.each(recipients, function (idx, recipient_data) {
_.each(recipients, function (recipient_data) {
var name_string = exports.render_person(recipient_data);
delete exports.private_message_mapped[name_string];
var arr = exports.private_message_typeahead_list;

View File

@ -218,7 +218,7 @@ function copy_handler(e) {
window.setTimeout(function () {
selection = window.getSelection();
selection.removeAllRanges();
$.each(ranges, function (index, range) {
_.each(ranges, function (range) {
selection.addRange(range);
});
$('#copytempdiv').remove();
@ -523,11 +523,11 @@ function toggle_star(row_id) {
// Avoid a full re-render, but update the star in each message
// table in which it is visible.
$.each([all_msg_list, home_msg_list, narrowed_msg_list], function () {
if (this === undefined) {
_.each([all_msg_list, home_msg_list, narrowed_msg_list], function (list) {
if (list === undefined) {
return;
}
var row = rows.get(row_id, this.table_name);
var row = rows.get(row_id, list.table_name);
if (row === undefined) {
// The row may not exist, e.g. if you star a message in the all
// messages table from a stream that isn't in your home view.
@ -544,9 +544,9 @@ function toggle_star(row_id) {
}
function update_gravatars() {
$.each($(".gravatar-profile"), function (index, profile) {
_.each($(".gravatar-profile"), function (profile) {
// Avatar URLs will have at least one param, so & is safe here.
$(this).attr('src', $(this).attr('src') + '&stamp=' + gravatar_stamp);
$(profile).attr('src', $(profile).attr('src') + '&stamp=' + gravatar_stamp);
});
gravatar_stamp += 1;
}
@ -1397,7 +1397,7 @@ exports.restore_compose_cursor = function () {
.caret(saved_compose_cursor, saved_compose_cursor);
};
exports.process_condensing = function (index, elem) {
exports.process_condensing = function (elem) {
var content = $(elem).find(".message_content");
var message = current_msg_list.get(rows.id($(elem)));
if (content !== undefined && message !== undefined) {

View File

@ -99,7 +99,7 @@ function in_viewport_or_tall(el, top_of_feed, bottom_of_feed) {
function add_to_visible_messages(candidates, visible_messages,
top_of_feed, bottom_of_feed) {
$.each(candidates, function (idx, row) {
_.each(candidates, function (row) {
var row_rect = row.getBoundingClientRect();
// Mark very tall messages as read once we've gotten past them
if (in_viewport_or_tall(row, top_of_feed, bottom_of_feed)) {

View File

@ -81,7 +81,7 @@ function update_person(person) {
}
$(function () {
$.each(page_params.people_list, function (idx, person) {
_.each(page_params.people_list, function (person) {
people_dict[person.email] = person;
person.pm_recipient_count = 0;
});
@ -275,7 +275,7 @@ function update_unread_counts() {
}
function mark_all_as_read(cont) {
$.each(all_msg_list.all(), function (idx, msg) {
_.each(all_msg_list.all(), function (msg) {
msg.flags = msg.flags || [];
msg.flags.push('read');
});
@ -301,7 +301,7 @@ function process_loaded_for_unread(messages) {
// Takes a list of messages and marks them as read
function process_read_messages(messages) {
var processed = [];
$.each(messages, function (idx, message) {
_.each(messages, function (message) {
message.flags = message.flags || [];
message.flags.push('read');
@ -477,7 +477,7 @@ $(function () {
messages = message_range(event.msg_list, event.previously_selected, event.id);
}
mark_messages_as_read(messages);
$.each(messages, function (idx, message) {
_.each(messages, function (message) {
message_tour.visit(message.id);
});
}
@ -599,7 +599,7 @@ function add_message_metadata(message) {
}
// Add new people involved in this message to the people list
$.each(involved_people, function (idx, person) {
_.each(involved_people, function (person) {
// Do the hasOwnProperty() call via the prototype to avoid problems
// with keys like "hasOwnProperty"
if (people_dict[person.email] === undefined) {
@ -626,7 +626,7 @@ function add_messages_helper(messages, msg_list, predicate, messages_are_new) {
if (msg_list.selected_id() === -1 && msg_list.empty()) {
bottom_messages = _.filter(messages, predicate);
} else {
$.each(messages, function (idx, msg) {
_.each(messages, function (msg) {
// Filter out duplicates that are already in msg_list, and all messages
// that fail our filter predicate
if (! (msg_list.get(msg.id) === undefined && predicate(msg))) {
@ -695,7 +695,7 @@ function deduplicate_messages(messages) {
function maybe_add_narrowed_messages(messages, msg_list, messages_are_new) {
var ids = [];
$.each(messages, function (idx, elem) {
_.each(messages, function (elem) {
ids.push(elem.id);
});
@ -713,7 +713,7 @@ function maybe_add_narrowed_messages(messages, msg_list, messages_are_new) {
}
var new_messages = [];
$.each(messages, function (idx, elem) {
_.each(messages, function (elem) {
if (data.messages.hasOwnProperty(elem.id)) {
elem.match_subject = data.messages[elem.id].match_subject;
elem.match_content = data.messages[elem.id].match_content;
@ -739,7 +739,7 @@ function maybe_add_narrowed_messages(messages, msg_list, messages_are_new) {
}
function update_messages(events) {
$.each(events, function (idx, event) {
_.each(events, function (event) {
var msg = all_msg_list.get(event.message_id);
if (msg === undefined) {
return;
@ -802,7 +802,7 @@ function get_updates_success(data) {
events_stored_during_tutorial = [];
}
$.each(data.events, function (idx, event) {
_.each(data.events, function (event) {
get_updates_params.last_event_id = Math.max(get_updates_params.last_event_id,
event.id);
@ -835,12 +835,12 @@ function get_updates_success(data) {
break;
case 'subscriptions':
if (event.op === 'add') {
$.each(event.subscriptions, function (index, subscription) {
_.each(event.subscriptions, function (subscription) {
$(document).trigger($.Event('subscription_add.zulip',
{subscription: subscription}));
});
} else if (event.op === 'remove') {
$.each(event.subscriptions, function (index, subscription) {
_.each(event.subscriptions, function (subscription) {
$(document).trigger($.Event('subscription_remove.zulip',
{subscription: subscription}));
});