mirror of https://github.com/zulip/zulip.git
js: Convert _.defaults to spread syntax.
This is not always a behavior-preserving translation: _.defaults mutates its first argument. However, the code does not always appear to have been written to expect that. Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
parent
dbffb2a614
commit
fe082248cc
|
@ -62,13 +62,15 @@ run_test('msg_edited_vars', () => {
|
|||
if (message === undefined) {
|
||||
message = {};
|
||||
}
|
||||
message_context = _.defaults(message_context, {
|
||||
message_context = {
|
||||
include_sender: true,
|
||||
});
|
||||
message_context.msg = _.defaults(message, {
|
||||
...message_context,
|
||||
};
|
||||
message_context.msg = {
|
||||
is_me_message: false,
|
||||
last_edit_timestamp: next_timestamp += 1,
|
||||
});
|
||||
...message,
|
||||
};
|
||||
return message_context;
|
||||
}
|
||||
|
||||
|
@ -133,10 +135,11 @@ run_test('merge_message_groups', () => {
|
|||
if (message === undefined) {
|
||||
message = {};
|
||||
}
|
||||
message_context = _.defaults(message_context, {
|
||||
message_context = {
|
||||
include_sender: true,
|
||||
});
|
||||
message_context.msg = _.defaults(message, {
|
||||
...message_context,
|
||||
};
|
||||
message_context.msg = {
|
||||
id: _.uniqueId('test_message_'),
|
||||
status_message: false,
|
||||
type: 'stream',
|
||||
|
@ -144,7 +147,8 @@ run_test('merge_message_groups', () => {
|
|||
topic: 'Test Subject 1',
|
||||
sender_email: 'test@example.com',
|
||||
timestamp: next_timestamp += 1,
|
||||
});
|
||||
...message,
|
||||
};
|
||||
return message_context;
|
||||
}
|
||||
|
||||
|
|
|
@ -120,12 +120,13 @@ exports.activate = function (raw_operators, opts) {
|
|||
trigger: opts ? opts.trigger : undefined,
|
||||
previous_id: current_msg_list.selected_id()});
|
||||
|
||||
opts = _.defaults({}, opts, {
|
||||
opts = {
|
||||
then_select_id: -1,
|
||||
then_select_offset: undefined,
|
||||
change_hash: true,
|
||||
trigger: 'unknown',
|
||||
});
|
||||
...opts,
|
||||
};
|
||||
|
||||
const id_info = {
|
||||
target_id: undefined,
|
||||
|
@ -678,13 +679,13 @@ exports.by_topic = function (target_id, opts) {
|
|||
{operator: 'stream', operand: original.stream},
|
||||
{operator: 'topic', operand: original.topic},
|
||||
];
|
||||
opts = _.defaults({}, opts, {then_select_id: target_id});
|
||||
opts = { then_select_id: target_id, ...opts };
|
||||
exports.activate(search_terms, opts);
|
||||
};
|
||||
|
||||
// Called for the 'narrow by stream' hotkey.
|
||||
exports.by_recipient = function (target_id, opts) {
|
||||
opts = _.defaults({}, opts, {then_select_id: target_id});
|
||||
opts = { then_select_id: target_id, ...opts };
|
||||
// don't use current_msg_list as it won't work for muted messages or for out-of-narrow links
|
||||
const message = message_store.get(target_id);
|
||||
|
||||
|
|
|
@ -220,13 +220,14 @@ function do_reload_app(send_after_reload, save_pointer, save_narrow, save_compos
|
|||
}
|
||||
|
||||
exports.initiate = function (options) {
|
||||
options = _.defaults({}, options, {
|
||||
options = {
|
||||
immediate: false,
|
||||
save_pointer: true,
|
||||
save_narrow: true,
|
||||
save_compose: true,
|
||||
send_after_reload: false,
|
||||
});
|
||||
...options,
|
||||
};
|
||||
|
||||
if (options.save_pointer === undefined ||
|
||||
options.save_narrow === undefined ||
|
||||
|
|
|
@ -59,7 +59,7 @@ exports.set_colorpicker_color = function (colorpicker, color) {
|
|||
};
|
||||
|
||||
exports.update_stream_color = function (sub, color, opts) {
|
||||
opts = _.defaults({}, opts, {update_historical: false});
|
||||
opts = { update_historical: false, ...opts };
|
||||
sub.color = color;
|
||||
const stream_id = sub.stream_id;
|
||||
// The swatch in the subscription row header.
|
||||
|
|
|
@ -666,10 +666,11 @@ exports.is_user_subscribed = function (stream_name, user_id) {
|
|||
exports.create_streams = function (streams) {
|
||||
for (const stream of streams) {
|
||||
// We handle subscriber stuff in other events.
|
||||
const attrs = _.defaults(stream, {
|
||||
const attrs = {
|
||||
subscribers: [],
|
||||
subscribed: false,
|
||||
});
|
||||
...stream,
|
||||
};
|
||||
exports.create_sub_from_server_data(stream.name, attrs);
|
||||
}
|
||||
};
|
||||
|
@ -698,7 +699,7 @@ exports.create_sub_from_server_data = function (stream_name, attrs) {
|
|||
|
||||
delete attrs.subscribers;
|
||||
|
||||
sub = _.defaults(attrs, {
|
||||
sub = {
|
||||
name: stream_name,
|
||||
render_subscribers: !page_params.realm_is_zephyr_mirror_realm || attrs.invite_only === true,
|
||||
subscribed: true,
|
||||
|
@ -712,7 +713,8 @@ exports.create_sub_from_server_data = function (stream_name, attrs) {
|
|||
description: '',
|
||||
rendered_description: '',
|
||||
first_message_id: attrs.first_message_id,
|
||||
});
|
||||
...attrs,
|
||||
};
|
||||
|
||||
exports.set_subscribers(sub, subscriber_user_ids);
|
||||
|
||||
|
|
Loading…
Reference in New Issue