mirror of
https://github.com/discourse/discourse.git
synced 2025-04-02 02:18:17 +08: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,
|
configurable: true,
|
||||||
get() {
|
get() {
|
||||||
const bound = emberBind(this, descriptor.value);
|
const bound = emberBind(this, descriptor.value);
|
||||||
const attributes = Object.assign({}, descriptor, {
|
const attributes = { ...descriptor, value: bound };
|
||||||
value: bound,
|
|
||||||
});
|
|
||||||
|
|
||||||
Object.defineProperty(this, name, attributes);
|
Object.defineProperty(this, name, attributes);
|
||||||
|
|
||||||
|
@ -90,10 +90,7 @@ export default class DiscoursePopover extends Component {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const instance = tippy(
|
const instance = tippy(target, { ...baseOptions, ...(this.options || {}) });
|
||||||
target,
|
|
||||||
Object.assign({}, baseOptions, this.options || {})
|
|
||||||
);
|
|
||||||
|
|
||||||
return instance?.id ? instance : null;
|
return instance?.id ? instance : null;
|
||||||
}
|
}
|
||||||
|
@ -102,12 +102,10 @@ export default Component.extend({
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (this.relativeDate) {
|
if (this.relativeDate) {
|
||||||
defaultOptions = Object.assign({}, defaultOptions, {
|
defaultOptions.minDate = moment(this.relativeDate).toDate();
|
||||||
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);
|
this.onChange(newState);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -32,10 +32,9 @@ export default Controller.extend({
|
|||||||
scoreTypes(types) {
|
scoreTypes(types) {
|
||||||
const username = I18n.t("review.example_username");
|
const username = I18n.t("review.example_username");
|
||||||
|
|
||||||
return types.map((type) =>
|
return types.map((type) => ({
|
||||||
Object.assign({}, type, {
|
...type,
|
||||||
title: type.title.replace("%{username}", username),
|
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";
|
import { getOwner, setOwner } from "@ember/application";
|
||||||
|
|
||||||
function renderRaw(ctx, template, templateName, params) {
|
function renderRaw(ctx, template, templateName, params) {
|
||||||
params = Object.assign({}, params);
|
params = { ...params };
|
||||||
params.parent = params.parent || ctx;
|
params.parent ||= ctx;
|
||||||
|
|
||||||
let context = helperContext();
|
let context = helperContext();
|
||||||
if (!params.view) {
|
if (!params.view) {
|
||||||
@ -18,7 +18,7 @@ function renderRaw(ctx, template, templateName, params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!params.view) {
|
if (!params.view) {
|
||||||
params = Object.assign({}, params, context);
|
params = { ...params, ...context };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ function parseCookieValue(s) {
|
|||||||
function cookie(key, value, options) {
|
function cookie(key, value, options) {
|
||||||
// Write
|
// Write
|
||||||
if (value !== undefined) {
|
if (value !== undefined) {
|
||||||
options = Object.assign({}, options || {});
|
options = { ...(options || {}) };
|
||||||
|
|
||||||
if (typeof options.expires === "number") {
|
if (typeof options.expires === "number") {
|
||||||
let days = options.expires,
|
let days = options.expires,
|
||||||
@ -71,7 +71,7 @@ export function removeCookie(key, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Must not alter options, thus extending a fresh object...
|
// Must not alter options, thus extending a fresh object...
|
||||||
cookie(key, "", Object.assign({}, options || {}, { expires: -1 }));
|
cookie(key, "", { ...(options || {}), expires: -1 });
|
||||||
return !cookie(key);
|
return !cookie(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ export default function (node, words, opts = {}) {
|
|||||||
matchCase: false,
|
matchCase: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
settings = Object.assign({}, settings, opts);
|
settings = { ...settings, ...opts };
|
||||||
words = makeArray(words)
|
words = makeArray(words)
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.map((word) => word.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&"));
|
.map((word) => word.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&"));
|
||||||
@ -74,7 +74,7 @@ export function unhighlightHTML(opts = {}) {
|
|||||||
className: "highlighted",
|
className: "highlighted",
|
||||||
};
|
};
|
||||||
|
|
||||||
settings = Object.assign({}, settings, opts);
|
settings = { ...settings, ...opts };
|
||||||
|
|
||||||
document
|
document
|
||||||
.querySelectorAll(`${settings.nodeName}.${settings.className}`)
|
.querySelectorAll(`${settings.nodeName}.${settings.className}`)
|
||||||
|
@ -54,7 +54,7 @@ const TopicList = RestModel.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
updateSortParams(order, ascending) {
|
updateSortParams(order, ascending) {
|
||||||
let params = Object.assign({}, this.params || {});
|
let params = { ...(this.params || {}) };
|
||||||
|
|
||||||
if (params.q) {
|
if (params.q) {
|
||||||
// search is unique, nothing else allowed with it
|
// search is unique, nothing else allowed with it
|
||||||
@ -68,7 +68,7 @@ const TopicList = RestModel.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
updateNewListSubsetParam(subset) {
|
updateNewListSubsetParam(subset) {
|
||||||
let params = Object.assign({}, this.params || {});
|
let params = { ...(this.params || {}) };
|
||||||
|
|
||||||
if (params.q) {
|
if (params.q) {
|
||||||
params = { q: 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
|
// A helper to build a topic route for a filter
|
||||||
export function filterQueryParams(params, defaultParams) {
|
export function filterQueryParams(params, defaultParams) {
|
||||||
const findOpts = Object.assign({}, defaultParams || {});
|
const findOpts = { ...(defaultParams || {}) };
|
||||||
|
|
||||||
if (params) {
|
if (params) {
|
||||||
Object.keys(queryParams).forEach(function (opt) {
|
Object.keys(queryParams).forEach(function (opt) {
|
||||||
|
@ -246,10 +246,11 @@ export default DiscourseRoute.extend({
|
|||||||
const categoryId = controller.category?.id;
|
const categoryId = controller.category?.id;
|
||||||
|
|
||||||
if (categoryId) {
|
if (categoryId) {
|
||||||
options = Object.assign({}, options, {
|
options = {
|
||||||
|
...options,
|
||||||
categoryId,
|
categoryId,
|
||||||
includeSubcategories: !controller.noSubcategories,
|
includeSubcategories: !controller.noSubcategories,
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
controller.send("dismissRead", operationType, options);
|
controller.send("dismissRead", operationType, options);
|
||||||
|
@ -315,7 +315,7 @@ const TopicRoute = DiscourseRoute.extend({
|
|||||||
this.setupParams(topic, queryParams);
|
this.setupParams(topic, queryParams);
|
||||||
return topic;
|
return topic;
|
||||||
} else {
|
} else {
|
||||||
let props = Object.assign({}, params);
|
let props = { ...params };
|
||||||
delete props.username_filters;
|
delete props.username_filters;
|
||||||
delete props.filter;
|
delete props.filter;
|
||||||
topic = this.store.createRecord("topic", props);
|
topic = this.store.createRecord("topic", props);
|
||||||
|
@ -132,7 +132,7 @@ export default class ScreenTrack extends Service {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
found.topicTime += topicTime;
|
found.topicTime += topicTime;
|
||||||
found.timings = Object.assign({}, timings, found.timings);
|
found.timings = { ...timings, ...found.timings };
|
||||||
} else {
|
} else {
|
||||||
this._consolidatedTimings.push({ timings, topicTime, topicId });
|
this._consolidatedTimings.push({ timings, topicTime, topicId });
|
||||||
}
|
}
|
||||||
|
@ -558,7 +558,7 @@ export default createWidget("header", {
|
|||||||
|
|
||||||
return h(
|
return h(
|
||||||
"div.wrap",
|
"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", () => {
|
server.get("/admin/site_settings", () => {
|
||||||
const fixtures = siteSettingFixture["/admin/site_settings"].site_settings;
|
const fixtures = siteSettingFixture["/admin/site_settings"].site_settings;
|
||||||
const titleSetting = Object.assign({}, fixtures[0]);
|
const titleSetting = { ...fixtures[0] };
|
||||||
|
|
||||||
if (updatedTitle) {
|
if (updatedTitle) {
|
||||||
titleSetting.value = updatedTitle;
|
titleSetting.value = updatedTitle;
|
||||||
|
@ -49,7 +49,7 @@ export async function joinChannel(name, user) {
|
|||||||
await publishToMessageBus(
|
await publishToMessageBus(
|
||||||
`/presence${name}`,
|
`/presence${name}`,
|
||||||
{
|
{
|
||||||
entering_users: [Object.assign({}, user)],
|
entering_users: [{ ...user }],
|
||||||
},
|
},
|
||||||
0,
|
0,
|
||||||
channel.last_message_id
|
channel.last_message_id
|
||||||
|
@ -8,7 +8,7 @@ module("Unit | Utility | i18n", function (hooks) {
|
|||||||
this._fallbackLocale = I18n.fallbackLocale;
|
this._fallbackLocale = I18n.fallbackLocale;
|
||||||
this._translations = I18n.translations;
|
this._translations = I18n.translations;
|
||||||
this._extras = I18n.extras;
|
this._extras = I18n.extras;
|
||||||
this._pluralizationRules = Object.assign({}, I18n.pluralizationRules);
|
this._pluralizationRules = { ...I18n.pluralizationRules };
|
||||||
|
|
||||||
I18n.locale = "fr";
|
I18n.locale = "fr";
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ module("Unit | Utility | i18n", function (hooks) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// fake pluralization rules
|
// fake pluralization rules
|
||||||
I18n.pluralizationRules = Object.assign({}, I18n.pluralizationRules);
|
I18n.pluralizationRules = { ...I18n.pluralizationRules };
|
||||||
I18n.pluralizationRules.fr = function (n) {
|
I18n.pluralizationRules.fr = function (n) {
|
||||||
if (n === 0) {
|
if (n === 0) {
|
||||||
return "zero";
|
return "zero";
|
||||||
|
@ -42,7 +42,7 @@ export default UserChooserComponent.extend({
|
|||||||
reconstructed.name = item.full_name;
|
reconstructed.name = item.full_name;
|
||||||
reconstructed.isGroup = true;
|
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-${type}-results`
|
||||||
: "discourse-poll-pie-chart";
|
: "discourse-poll-pie-chart";
|
||||||
contents.push(
|
contents.push(
|
||||||
this.attach(
|
this.attach(resultsWidget, { ...attrs, voters: state.voters })
|
||||||
resultsWidget,
|
|
||||||
Object.assign({}, attrs, { voters: state.voters })
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return contents;
|
return contents;
|
||||||
@ -903,7 +900,8 @@ export default createWidget("discourse-poll", {
|
|||||||
(attrs.post.get("topic.archived") && !staffOnly) ||
|
(attrs.post.get("topic.archived") && !staffOnly) ||
|
||||||
(this.isClosed() && !staffOnly);
|
(this.isClosed() && !staffOnly);
|
||||||
|
|
||||||
const newAttrs = Object.assign({}, attrs, {
|
const newAttrs = {
|
||||||
|
...attrs,
|
||||||
canCastVotes: this.canCastVotes(),
|
canCastVotes: this.canCastVotes(),
|
||||||
hasVoted: this.hasVoted(),
|
hasVoted: this.hasVoted(),
|
||||||
isAutomaticallyClosed: this.isAutomaticallyClosed(),
|
isAutomaticallyClosed: this.isAutomaticallyClosed(),
|
||||||
@ -912,7 +910,7 @@ export default createWidget("discourse-poll", {
|
|||||||
max: this.max(),
|
max: this.max(),
|
||||||
min: this.min(),
|
min: this.min(),
|
||||||
showResults,
|
showResults,
|
||||||
});
|
};
|
||||||
|
|
||||||
return [
|
return [
|
||||||
this.attach("discourse-poll-container", newAttrs),
|
this.attach("discourse-poll-container", newAttrs),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user