mirror of
https://github.com/discourse/discourse.git
synced 2025-02-16 18:24:52 -06:00
DEV: Use object spread instead of Object.assign({}, …)
(#23167)
Same behavior, more consistent and concise code.
This commit is contained in:
parent
4a4c91b0a1
commit
c48e29db02
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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() });
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -39,7 +39,7 @@ export default Component.extend({
|
||||
}
|
||||
}
|
||||
|
||||
const newState = Object.assign({}, state, diff);
|
||||
const newState = { ...state, ...diff };
|
||||
this.onChange(newState);
|
||||
}
|
||||
},
|
||||
|
@ -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),
|
||||
}));
|
||||
},
|
||||
});
|
||||
|
@ -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 };
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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}`)
|
||||
|
@ -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 };
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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 });
|
||||
}
|
||||
|
@ -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 })
|
||||
);
|
||||
},
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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";
|
||||
|
@ -42,7 +42,7 @@ export default UserChooserComponent.extend({
|
||||
reconstructed.name = item.full_name;
|
||||
reconstructed.isGroup = true;
|
||||
}
|
||||
return Object.assign({}, item, reconstructed);
|
||||
return { ...item, ...reconstructed };
|
||||
});
|
||||
});
|
||||
},
|
||||
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user