DEV: Use object spread instead of Object.assign (#30407)

This commit is contained in:
Jarek Radosz
2024-12-23 08:44:29 +01:00
committed by GitHub
parent 6f01584607
commit 0336235c74
9 changed files with 26 additions and 40 deletions

View File

@ -14,10 +14,7 @@ export function deepMerge(...objects) {
if (Array.isArray(targetValue) && Array.isArray(sourceValue)) { if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
target[key] = targetValue.concat(sourceValue); target[key] = targetValue.concat(sourceValue);
} else if (isObject(targetValue) && isObject(sourceValue)) { } else if (isObject(targetValue) && isObject(sourceValue)) {
target[key] = deepMergeInner( target[key] = deepMergeInner({ ...targetValue }, sourceValue);
Object.assign({}, targetValue),
sourceValue
);
} else { } else {
target[key] = sourceValue; target[key] = sourceValue;
} }

View File

@ -208,7 +208,7 @@ export function duration(distance, ageOpts) {
} }
export function durationTiny(distance, ageOpts) { export function durationTiny(distance, ageOpts) {
return duration(distance, Object.assign({ format: "tiny" }, ageOpts)); return duration(distance, { format: "tiny", ...ageOpts });
} }
function relativeAgeTiny(date, ageOpts) { function relativeAgeTiny(date, ageOpts) {

View File

@ -275,9 +275,7 @@ export default {
addShortcut(shortcut, callback, opts = {}) { addShortcut(shortcut, callback, opts = {}) {
// we trim but leave whitespace between characters, as shortcuts // we trim but leave whitespace between characters, as shortcuts
// like `z z` are valid for ItsATrap // like `z z` are valid for ItsATrap
shortcut = shortcut.trim(); this.bindKey(shortcut.trim(), { handler: callback, ...opts });
let newBinding = Object.assign({ handler: callback }, opts);
this.bindKey(shortcut, newBinding);
if (opts.help) { if (opts.help) {
addExtraKeyboardShortcutHelp(opts.help); addExtraKeyboardShortcutHelp(opts.help);
} }

View File

@ -429,7 +429,7 @@ export default class Group extends RestModel {
save(opts = {}) { save(opts = {}) {
return ajax(`/groups/${this.id}`, { return ajax(`/groups/${this.id}`, {
type: "PUT", type: "PUT",
data: Object.assign({ group: this.asJSON() }, opts), data: { group: this.asJSON(), ...opts },
}); });
} }

View File

@ -1347,12 +1347,10 @@ acceptance("composer buttons API", function (needs) {
const editor = document.querySelector(".d-editor-input"); const editor = document.querySelector(".d-editor-input");
editor.setSelectionRange(6, 9); // select the text input in the composer editor.setSelectionRange(6, 9); // select the text input in the composer
await triggerKeyEvent( await triggerKeyEvent(".d-editor-input", "keydown", "B", {
".d-editor-input", altKey: true,
"keydown", ...metaModifier,
"B", });
Object.assign({ altKey: true }, metaModifier)
);
assert assert
.dom(".d-editor-input") .dom(".d-editor-input")
@ -1401,12 +1399,10 @@ acceptance("composer buttons API", function (needs) {
await click(".post-controls button.reply"); await click(".post-controls button.reply");
const editor = document.querySelector(".d-editor-input"); const editor = document.querySelector(".d-editor-input");
await triggerKeyEvent( await triggerKeyEvent(".d-editor-input", "keydown", "S", {
".d-editor-input", altKey: true,
"keydown", ...metaModifier,
"S", });
Object.assign({ altKey: true }, metaModifier)
);
assert.dom(editor).hasValue(":smile: from keyboard"); assert.dom(editor).hasValue(":smile: from keyboard");
}); });

View File

@ -558,17 +558,13 @@ export default class ChatChannel extends Component {
} }
try { try {
const params = { await this.chatApi.sendMessage(this.args.channel.id, {
message: message.message, message: message.message,
in_reply_to_id: message.inReplyTo?.id, in_reply_to_id: message.inReplyTo?.id,
staged_id: message.id, staged_id: message.id,
upload_ids: message.uploads.map((upload) => upload.id), upload_ids: message.uploads.map((upload) => upload.id),
}; ...extractCurrentTopicInfo(this),
});
await this.chatApi.sendMessage(
this.args.channel.id,
Object.assign({}, params, extractCurrentTopicInfo(this))
);
if (!this.capabilities.isIOS) { if (!this.capabilities.isIOS) {
this.scrollToLatestMessage(); this.scrollToLatestMessage();

View File

@ -442,17 +442,16 @@ export default class ChatThread extends Component {
} }
try { try {
const params = {
message: message.message,
in_reply_to_id: null,
staged_id: message.id,
upload_ids: message.uploads.map((upload) => upload.id),
thread_id: message.thread.id,
};
const response = await this.chatApi.sendMessage( const response = await this.chatApi.sendMessage(
this.args.thread.channel.id, this.args.thread.channel.id,
Object.assign({}, params, extractCurrentTopicInfo(this)) {
message: message.message,
in_reply_to_id: null,
staged_id: message.id,
upload_ids: message.uploads.map((upload) => upload.id),
thread_id: message.thread.id,
...extractCurrentTopicInfo(this),
}
); );
this.args.thread.currentUserMembership ??= this.args.thread.currentUserMembership ??=

View File

@ -81,7 +81,7 @@ export default class ChatFabricators {
status: args.status || CHANNEL_STATUSES.open, status: args.status || CHANNEL_STATUSES.open,
slug: slug:
chatable?.slug || chatable instanceof Category ? chatable.slug : null, chatable?.slug || chatable instanceof Category ? chatable.slug : null,
meta: Object.assign({ can_delete_self: true }, args.meta || {}), meta: { can_delete_self: true, ...(args.meta || {}) },
archive_failed: args.archive_failed ?? false, archive_failed: args.archive_failed ?? false,
memberships_count: args.memberships_count ?? 0, memberships_count: args.memberships_count ?? 0,
}); });

View File

@ -479,7 +479,7 @@ export default class PollComponent extends Component {
voters = preloadedVoters; voters = preloadedVoters;
} }
this.preloadedVoters = Object.assign({}, preloadedVoters); this.preloadedVoters = { ...preloadedVoters };
const votersCount = voters?.length; const votersCount = voters?.length;
return ajax("/polls/voters.json", { return ajax("/polls/voters.json", {
@ -535,7 +535,7 @@ export default class PollComponent extends Component {
if (optionId) { if (optionId) {
preloadedVoters[optionId].loading = false; preloadedVoters[optionId].loading = false;
} }
this.preloadedVoters = Object.assign({}, preloadedVoters); this.preloadedVoters = { ...preloadedVoters };
}); });
} }