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 // realm
function test_realm_boolean(event, parameter_name) { function test_realm_boolean(event, parameter_name) {
page_params[parameter_name] = true; page_params[parameter_name] = true;
event = _.clone(event); event = { ...event };
event.value = false; event.value = false;
dispatch(event); dispatch(event);
assert.equal(page_params[parameter_name], false); assert.equal(page_params[parameter_name], false);
event = _.clone(event); event = { ...event };
event.value = true; event.value = true;
dispatch(event); dispatch(event);
assert.equal(page_params[parameter_name], true); assert.equal(page_params[parameter_name], true);

View File

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

View File

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

View File

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

View File

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