Skip to content

A platform for community discussion. Free, open, simple.

DEV: Use object spread instead of `Object.assign({}, …)` (#23167)

Jarek Radoszc48e29db02f0
diff --git a/app/assets/javascripts/discourse-common/addon/utils/decorators.js b/app/assets/javascripts/discourse-common/addon/utils/decorators.js
index a6519aab200..56bab146578 100644
--- a/app/assets/javascripts/discourse-common/addon/utils/decorators.js
+++ b/app/assets/javascripts/discourse-common/addon/utils/decorators.js
@@ -72,9 +72,7 @@ export function bind(target, name, descriptor) {
configurable: true,
get() {
const bound = emberBind(this, descriptor.value);
- const attributes = Object.assign({}, descriptor, {
- value: bound,
- });
+ const attributes = { ...descriptor, value: bound };
Object.defineProperty(this, name, attributes);
diff --git a/app/assets/javascripts/discourse/app/components/d-popover.js b/app/assets/javascripts/discourse/app/components/d-popover.js
index 930f16348f2..86534f8e2bf 100644
--- a/app/assets/javascripts/discourse/app/components/d-popover.js
+++ b/app/assets/javascripts/discourse/app/components/d-popover.js
@@ -90,10 +90,7 @@ export default class DiscoursePopover extends Component {
return null;
}
- const instance = tippy(
- target,
- Object.assign({}, baseOptions, this.options || {})
- );
+ const instance = tippy(target, { ...baseOptions, ...(this.options || {}) });
return instance?.id ? instance : null;
}
diff --git a/app/assets/javascripts/discourse/app/components/date-input.js b/app/assets/javascripts/discourse/app/components/date-input.js
index 61192bc5e59..48ca9d19b04 100644
--- a/app/assets/javascripts/discourse/app/components/date-input.js
+++ b/app/assets/javascripts/discourse/app/components/date-input.js
@@ -102,12 +102,10 @@ export default Component.extend({
};
if (this.relativeDate) {
- defaultOptions = Object.assign({}, defaultOptions, {
- minDate: moment(this.relativeDate).toDate(),
- });
+ defaultOptions.minDate = moment(this.relativeDate).toDate();
}
- return new Pikaday(Object.assign({}, defaultOptions, this._opts()));
+ return new Pikaday({ ...defaultOptions, ...this._opts() });
});
},
diff --git a/app/assets/javascripts/discourse/app/components/date-time-input-range.js b/app/assets/javascripts/discourse/app/components/date-time-input-range.js
index bea9f2795b7..a9966925ace 100644
--- a/app/assets/javascripts/discourse/app/components/date-time-input-range.js
+++ b/app/assets/javascripts/discourse/app/components/date-time-input-range.js
@@ -39,7 +39,7 @@ export default Component.extend({
}
}
- const newState = Object.assign({}, state, diff);
+ const newState = { ...state, ...diff };
this.onChange(newState);
}
},
diff --git a/app/assets/javascripts/discourse/app/controllers/review-settings.js b/app/assets/javascripts/discourse/app/controllers/review-settings.js
index 8ca69c88531..b48dd830ec1 100644
--- a/app/assets/javascripts/discourse/app/controllers/review-settings.js
+++ b/app/assets/javascripts/discourse/app/controllers/review-settings.js
@@ -32,10 +32,9 @@ export default Controller.extend({
scoreTypes(types) {
const username = I18n.t("review.example_username");
- return types.map((type) =>
- Object.assign({}, type, {
- title: type.title.replace("%{username}", username),
- })
- );
+ return types.map((type) => ({
+ ...type,
+ title: type.title.replace("%{username}", username),
+ }));
},
});
diff --git a/app/assets/javascripts/discourse/app/helpers/raw.js b/app/assets/javascripts/discourse/app/helpers/raw.js
index d138b54ac6e..ad7c2a70ea3 100644
--- a/app/assets/javascripts/discourse/app/helpers/raw.js
+++ b/app/assets/javascripts/discourse/app/helpers/raw.js
@@ -5,8 +5,8 @@ import { RUNTIME_OPTIONS } from "discourse-common/lib/raw-handlebars-helpers";
import { getOwner, setOwner } from "@ember/application";
function renderRaw(ctx, template, templateName, params) {
- params = Object.assign({}, params);
- params.parent = params.parent || ctx;
+ params = { ...params };
+ params.parent ||= ctx;
let context = helperContext();
if (!params.view) {
@@ -18,7 +18,7 @@ function renderRaw(ctx, template, templateName, params) {
}
if (!params.view) {
- params = Object.assign({}, params, context);
+ params = { ...params, ...context };
}
}
diff --git a/app/assets/javascripts/discourse/app/lib/cookie.js b/app/assets/javascripts/discourse/app/lib/cookie.js
index 43c0602e22e..936910bd542 100644
--- a/app/assets/javascripts/discourse/app/lib/cookie.js
+++ b/app/assets/javascripts/discourse/app/lib/cookie.js
@@ -20,7 +20,7 @@ function parseCookieValue(s) {
function cookie(key, value, options) {
// Write
if (value !== undefined) {
- options = Object.assign({}, options || {});
+ options = { ...(options || {}) };
if (typeof options.expires === "number") {
let days = options.expires,
@@ -71,7 +71,7 @@ export function removeCookie(key, options) {
}
// Must not alter options, thus extending a fresh object...
- cookie(key, "", Object.assign({}, options || {}, { expires: -1 }));
+ cookie(key, "", { ...(options || {}), expires: -1 });
return !cookie(key);
}
diff --git a/app/assets/javascripts/discourse/app/lib/highlight-html.js b/app/assets/javascripts/discourse/app/lib/highlight-html.js
index 3e7ffd87742..e43ab7373e6 100644
--- a/app/assets/javascripts/discourse/app/lib/highlight-html.js
+++ b/app/assets/javascripts/discourse/app/lib/highlight-html.js
@@ -42,7 +42,7 @@ export default function (node, words, opts = {}) {
matchCase: false,
};
- settings = Object.assign({}, settings, opts);
+ settings = { ...settings, ...opts };
words = makeArray(words)
.filter(Boolean)
.map((word) => word.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&"));
@@ -74,7 +74,7 @@ export function unhighlightHTML(opts = {}) {
className: "highlighted",
};
- settings = Object.assign({}, settings, opts);
+ settings = { ...settings, ...opts };
document
.querySelectorAll(`${settings.nodeName}.${settings.className}`)
diff --git a/app/assets/javascripts/discourse/app/models/topic-list.js b/app/assets/javascripts/discourse/app/models/topic-list.js
index b2be4198256..b0325f4f8df 100644
--- a/app/assets/javascripts/discourse/app/models/topic-list.js
+++ b/app/assets/javascripts/discourse/app/models/topic-list.js
@@ -54,7 +54,7 @@ const TopicList = RestModel.extend({
},
updateSortParams(order, ascending) {
- let params = Object.assign({}, this.params || {});
+ let params = { ...(this.params || {}) };
if (params.q) {
// search is unique, nothing else allowed with it
@@ -68,7 +68,7 @@ const TopicList = RestModel.extend({
},
updateNewListSubsetParam(subset) {
- let params = Object.assign({}, this.params || {});
+ let params = { ...(this.params || {}) };
if (params.q) {
params = { q: params.q };
diff --git a/app/assets/javascripts/discourse/app/routes/build-topic-route.js b/app/assets/javascripts/discourse/app/routes/build-topic-route.js
index 4b3ff79f25e..7cd5085e2f7 100644
--- a/app/assets/javascripts/discourse/app/routes/build-topic-route.js
+++ b/app/assets/javascripts/discourse/app/routes/build-topic-route.js
@@ -17,7 +17,7 @@ import User from "discourse/models/user";
// A helper to build a topic route for a filter
export function filterQueryParams(params, defaultParams) {
- const findOpts = Object.assign({}, defaultParams || {});
+ const findOpts = { ...(defaultParams || {}) };
if (params) {
Object.keys(queryParams).forEach(function (opt) {
diff --git a/app/assets/javascripts/discourse/app/routes/tag-show.js b/app/assets/javascripts/discourse/app/routes/tag-show.js
index 71322b846fd..fc4b5712313 100644
--- a/app/assets/javascripts/discourse/app/routes/tag-show.js
+++ b/app/assets/javascripts/discourse/app/routes/tag-show.js
@@ -246,10 +246,11 @@ export default DiscourseRoute.extend({
const categoryId = controller.category?.id;
if (categoryId) {
- options = Object.assign({}, options, {
+ options = {
+ ...options,
categoryId,
includeSubcategories: !controller.noSubcategories,
- });
+ };
}
controller.send("dismissRead", operationType, options);
diff --git a/app/assets/javascripts/discourse/app/routes/topic.js b/app/assets/javascripts/discourse/app/routes/topic.js
index 6a4539207af..3e996ff6357 100644
--- a/app/assets/javascripts/discourse/app/routes/topic.js
+++ b/app/assets/javascripts/discourse/app/routes/topic.js
@@ -315,7 +315,7 @@ const TopicRoute = DiscourseRoute.extend({
this.setupParams(topic, queryParams);
return topic;
} else {
- let props = Object.assign({}, params);
+ let props = { ...params };
delete props.username_filters;
delete props.filter;
topic = this.store.createRecord("topic", props);
diff --git a/app/assets/javascripts/discourse/app/services/screen-track.js b/app/assets/javascripts/discourse/app/services/screen-track.js
index aedc05402cf..c6a0294ac76 100644
--- a/app/assets/javascripts/discourse/app/services/screen-track.js
+++ b/app/assets/javascripts/discourse/app/services/screen-track.js
@@ -132,7 +132,7 @@ export default class ScreenTrack extends Service {
}
});
found.topicTime += topicTime;
- found.timings = Object.assign({}, timings, found.timings);
+ found.timings = { ...timings, ...found.timings };
} else {
this._consolidatedTimings.push({ timings, topicTime, topicId });
}
diff --git a/app/assets/javascripts/discourse/app/widgets/header.js b/app/assets/javascripts/discourse/app/widgets/header.js
index 9943b8d96ab..4cae0bd4552 100644
--- a/app/assets/javascripts/discourse/app/widgets/header.js
+++ b/app/assets/javascripts/discourse/app/widgets/header.js
@@ -558,7 +558,7 @@ export default createWidget("header", {
return h(
"div.wrap",
- this.attach("header-contents", Object.assign({}, attrs, contentsAttrs))
+ this.attach("header-contents", { ...attrs, ...contentsAttrs })
);
},
diff --git a/app/assets/javascripts/discourse/tests/acceptance/admin-site-settings-test.js b/app/assets/javascripts/discourse/tests/acceptance/admin-site-settings-test.js
index bf876817f5d..c51b34fd1d3 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/admin-site-settings-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/admin-site-settings-test.js
@@ -27,7 +27,7 @@ acceptance("Admin - Site Settings", function (needs) {
});
server.get("/admin/site_settings", () => {
const fixtures = siteSettingFixture["/admin/site_settings"].site_settings;
- const titleSetting = Object.assign({}, fixtures[0]);
+ const titleSetting = { ...fixtures[0] };
if (updatedTitle) {
titleSetting.value = updatedTitle;
diff --git a/app/assets/javascripts/discourse/tests/helpers/presence-pretender.js b/app/assets/javascripts/discourse/tests/helpers/presence-pretender.js
index c434f03d627..1a8dcea76ef 100644
--- a/app/assets/javascripts/discourse/tests/helpers/presence-pretender.js
+++ b/app/assets/javascripts/discourse/tests/helpers/presence-pretender.js
@@ -49,7 +49,7 @@ export async function joinChannel(name, user) {
await publishToMessageBus(
`/presence${name}`,
{
- entering_users: [Object.assign({}, user)],
+ entering_users: [{ ...user }],
},
0,
channel.last_message_id
diff --git a/app/assets/javascripts/discourse/tests/unit/lib/i18n-test.js b/app/assets/javascripts/discourse/tests/unit/lib/i18n-test.js
index 4746fad0121..2b739eaf9c1 100644
--- a/app/assets/javascripts/discourse/tests/unit/lib/i18n-test.js
+++ b/app/assets/javascripts/discourse/tests/unit/lib/i18n-test.js
@@ -8,7 +8,7 @@ module("Unit | Utility | i18n", function (hooks) {
this._fallbackLocale = I18n.fallbackLocale;
this._translations = I18n.translations;
this._extras = I18n.extras;
- this._pluralizationRules = Object.assign({}, I18n.pluralizationRules);
+ this._pluralizationRules = { ...I18n.pluralizationRules };
I18n.locale = "fr";
@@ -71,7 +71,7 @@ module("Unit | Utility | i18n", function (hooks) {
};
// fake pluralization rules
- I18n.pluralizationRules = Object.assign({}, I18n.pluralizationRules);
+ I18n.pluralizationRules = { ...I18n.pluralizationRules };
I18n.pluralizationRules.fr = function (n) {
if (n === 0) {
return "zero";
diff --git a/app/assets/javascripts/select-kit/addon/components/email-group-user-chooser.js b/app/assets/javascripts/select-kit/addon/components/email-group-user-chooser.js
index af4f881aacc..bea7b54d76f 100644
--- a/app/assets/javascripts/select-kit/addon/components/email-group-user-chooser.js
+++ b/app/assets/javascripts/select-kit/addon/components/email-group-user-chooser.js
@@ -42,7 +42,7 @@ export default UserChooserComponent.extend({
reconstructed.name = item.full_name;
reconstructed.isGroup = true;
}
- return Object.assign({}, item, reconstructed);
+ return { ...item, ...reconstructed };
});
});
},
diff --git a/plugins/poll/assets/javascripts/discourse/widgets/discourse-poll.js b/plugins/poll/assets/javascripts/discourse/widgets/discourse-poll.js
index 2fc41f9b937..518e70803fd 100644
--- a/plugins/poll/assets/javascripts/discourse/widgets/discourse-poll.js
+++ b/plugins/poll/assets/javascripts/discourse/widgets/discourse-poll.js
@@ -299,10 +299,7 @@ createWidget("discourse-poll-container", {
? `discourse-poll-${type}-results`
: "discourse-poll-pie-chart";
contents.push(
- this.attach(
- resultsWidget,
- Object.assign({}, attrs, { voters: state.voters })
- )
+ this.attach(resultsWidget, { ...attrs, voters: state.voters })
);
return contents;
@@ -903,7 +900,8 @@ export default createWidget("discourse-poll", {
(attrs.post.get("topic.archived") && !staffOnly) ||
(this.isClosed() && !staffOnly);
- const newAttrs = Object.assign({}, attrs, {
+ const newAttrs = {
+ ...attrs,
canCastVotes: this.canCastVotes(),
hasVoted: this.hasVoted(),
isAutomaticallyClosed: this.isAutomaticallyClosed(),
@@ -912,7 +910,7 @@ export default createWidget("discourse-poll", {
max: this.max(),
min: this.min(),
showResults,
- });
+ };
return [
this.attach("discourse-poll-container", newAttrs),