A platform for community discussion. Free, open, simple.
DEV: Use object spread instead of Object.assign (#30407)
Jarek Radosz0336235c74d2
diff --git a/app/assets/javascripts/discourse-common/addon/lib/object.js b/app/assets/javascripts/discourse-common/addon/lib/object.jsindex bea2109a1f8..ef51d669301 100644--- a/app/assets/javascripts/discourse-common/addon/lib/object.js+++ b/app/assets/javascripts/discourse-common/addon/lib/object.js@@ -14,10 +14,7 @@ export function deepMerge(...objects) {if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {target[key] = targetValue.concat(sourceValue);} else if (isObject(targetValue) && isObject(sourceValue)) {- target[key] = deepMergeInner(- Object.assign({}, targetValue),- sourceValue- );+ target[key] = deepMergeInner({ ...targetValue }, sourceValue);} else {target[key] = sourceValue;}diff --git a/app/assets/javascripts/discourse/app/lib/formatter.js b/app/assets/javascripts/discourse/app/lib/formatter.jsindex f0a88bdf1c4..148e0c7f111 100644--- a/app/assets/javascripts/discourse/app/lib/formatter.js+++ b/app/assets/javascripts/discourse/app/lib/formatter.js@@ -208,7 +208,7 @@ export function duration(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) {diff --git a/app/assets/javascripts/discourse/app/lib/keyboard-shortcuts.js b/app/assets/javascripts/discourse/app/lib/keyboard-shortcuts.jsindex f8cd9280289..1256dcc1467 100644--- a/app/assets/javascripts/discourse/app/lib/keyboard-shortcuts.js+++ b/app/assets/javascripts/discourse/app/lib/keyboard-shortcuts.js@@ -275,9 +275,7 @@ export default {addShortcut(shortcut, callback, opts = {}) {// we trim but leave whitespace between characters, as shortcuts// like `z z` are valid for ItsATrap- shortcut = shortcut.trim();- let newBinding = Object.assign({ handler: callback }, opts);- this.bindKey(shortcut, newBinding);+ this.bindKey(shortcut.trim(), { handler: callback, ...opts });if (opts.help) {addExtraKeyboardShortcutHelp(opts.help);}diff --git a/app/assets/javascripts/discourse/app/models/group.js b/app/assets/javascripts/discourse/app/models/group.jsindex 2fc65d3b2b1..b8b36e11ec8 100644--- a/app/assets/javascripts/discourse/app/models/group.js+++ b/app/assets/javascripts/discourse/app/models/group.js@@ -429,7 +429,7 @@ export default class Group extends RestModel {save(opts = {}) {return ajax(`/groups/${this.id}`, {type: "PUT",- data: Object.assign({ group: this.asJSON() }, opts),+ data: { group: this.asJSON(), ...opts },});}diff --git a/app/assets/javascripts/discourse/tests/acceptance/composer-test.js b/app/assets/javascripts/discourse/tests/acceptance/composer-test.jsindex c8d4233c25b..3e81e655bb5 100644--- a/app/assets/javascripts/discourse/tests/acceptance/composer-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/composer-test.js@@ -1347,12 +1347,10 @@ acceptance("composer buttons API", function (needs) {const editor = document.querySelector(".d-editor-input");editor.setSelectionRange(6, 9); // select the text input in the composer- await triggerKeyEvent(- ".d-editor-input",- "keydown",- "B",- Object.assign({ altKey: true }, metaModifier)- );+ await triggerKeyEvent(".d-editor-input", "keydown", "B", {+ altKey: true,+ ...metaModifier,+ });assert.dom(".d-editor-input")@@ -1401,12 +1399,10 @@ acceptance("composer buttons API", function (needs) {await click(".post-controls button.reply");const editor = document.querySelector(".d-editor-input");- await triggerKeyEvent(- ".d-editor-input",- "keydown",- "S",- Object.assign({ altKey: true }, metaModifier)- );+ await triggerKeyEvent(".d-editor-input", "keydown", "S", {+ altKey: true,+ ...metaModifier,+ });assert.dom(editor).hasValue(":smile: from keyboard");});diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjsindex bdaab6a9d9d..1cb2efe7895 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs@@ -558,17 +558,13 @@ export default class ChatChannel extends Component {}try {- const params = {+ await this.chatApi.sendMessage(this.args.channel.id, {message: message.message,in_reply_to_id: message.inReplyTo?.id,staged_id: message.id,upload_ids: message.uploads.map((upload) => upload.id),- };-- await this.chatApi.sendMessage(- this.args.channel.id,- Object.assign({}, params, extractCurrentTopicInfo(this))- );+ ...extractCurrentTopicInfo(this),+ });if (!this.capabilities.isIOS) {this.scrollToLatestMessage();diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjsindex b5020270b96..b5bdc774a0f 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjs@@ -442,17 +442,16 @@ export default class ChatThread extends Component {}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(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 ??=diff --git a/plugins/chat/assets/javascripts/discourse/lib/fabricators.js b/plugins/chat/assets/javascripts/discourse/lib/fabricators.jsindex ed5e8a9006a..655efe9392e 100644--- a/plugins/chat/assets/javascripts/discourse/lib/fabricators.js+++ b/plugins/chat/assets/javascripts/discourse/lib/fabricators.js@@ -81,7 +81,7 @@ export default class ChatFabricators {status: args.status || CHANNEL_STATUSES.open,slug: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,memberships_count: args.memberships_count ?? 0,});diff --git a/plugins/poll/assets/javascripts/discourse/components/poll.gjs b/plugins/poll/assets/javascripts/discourse/components/poll.gjsindex 85b48724c1e..e326ee4d99c 100644--- a/plugins/poll/assets/javascripts/discourse/components/poll.gjs+++ b/plugins/poll/assets/javascripts/discourse/components/poll.gjs@@ -479,7 +479,7 @@ export default class PollComponent extends Component {voters = preloadedVoters;}- this.preloadedVoters = Object.assign({}, preloadedVoters);+ this.preloadedVoters = { ...preloadedVoters };const votersCount = voters?.length;return ajax("/polls/voters.json", {@@ -535,7 +535,7 @@ export default class PollComponent extends Component {if (optionId) {preloadedVoters[optionId].loading = false;}- this.preloadedVoters = Object.assign({}, preloadedVoters);+ this.preloadedVoters = { ...preloadedVoters };});}