js: Convert _.clone(a) to { ...a } or a.slice().

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg 2020-02-08 19:44:12 -08:00 committed by Tim Abbott
parent c9dbd13189
commit 1087fbebfe
5 changed files with 11 additions and 13 deletions

View File

@ -888,11 +888,11 @@ with_overrides(function (override) {
// realm
function test_realm_boolean(event, parameter_name) {
page_params[parameter_name] = true;
event = _.clone(event);
event = { ...event };
event.value = false;
dispatch(event);
assert.equal(page_params[parameter_name], false);
event = _.clone(event);
event = { ...event };
event.value = true;
dispatch(event);
assert.equal(page_params[parameter_name], true);

View File

@ -122,9 +122,9 @@ run_test('draft_model', () => {
localStorage.clear();
(function test_addDraft() {
stub_timestamp(1, function () {
const expected = _.clone(draft_1);
const expected = { ...draft_1 };
expected.updatedAt = 1;
const id = draft_model.addDraft(_.clone(draft_1));
const id = draft_model.addDraft({ ...draft_1 });
assert.deepEqual(ls.get("drafts")[id], expected);
});
@ -134,9 +134,9 @@ run_test('draft_model', () => {
(function test_editDraft() {
stub_timestamp(2, function () {
ls.set("drafts", { id1: draft_1 });
const expected = _.clone(draft_2);
const expected = { ...draft_2 };
expected.updatedAt = 2;
draft_model.editDraft("id1", _.clone(draft_2));
draft_model.editDraft("id1", { ...draft_2 });
assert.deepEqual(ls.get("drafts").id1, expected);
});

View File

@ -110,9 +110,7 @@ zrequire('topic_data');
zrequire('message_store');
run_test('message_store', () => {
// Our test runner automatically sets _ for us.
// See http://underscorejs.org/ for help on that library.
const in_message = _.clone(messages.isaac_to_denmark_stream);
const in_message = { ...messages.isaac_to_denmark_stream };
assert.equal(in_message.alerted, undefined);
message_store.set_message_booleans(in_message);
@ -139,7 +137,7 @@ run_test('unread', () => {
assert.equal(unread.num_unread_for_topic(stream_id, topic_name), 0);
const in_message = _.clone(messages.isaac_to_denmark_stream);
const in_message = { ...messages.isaac_to_denmark_stream };
message_store.set_message_booleans(in_message);
unread.process_loaded_messages([in_message]);

View File

@ -54,7 +54,7 @@ run_test('activate', () => {
];
const opts = {
events: _.clone(events),
events: events.slice(),
extra_data: '',
message: {
id: 2001,

View File

@ -488,7 +488,7 @@ Filter.prototype = {
filter_with_new_topic: function (new_topic) {
const terms = this._operators.map(term => {
const new_term = _.clone(term);
const new_term = { ...term };
if (new_term.operator === 'topic' && !new_term.negated) {
new_term.operand = new_topic;
}
@ -626,7 +626,7 @@ Filter.sorted_term_types = function (term_types) {
return util.strcmp(a, b);
}
return _.clone(term_types).sort(compare);
return term_types.slice().sort(compare);
};
Filter.operator_to_prefix = function (operator, negated) {