mirror of
https://github.com/discourse/discourse.git
synced 2025-01-30 12:46:15 +08:00
DEV: Use object spread instead of Object.assign (#30407)
This commit is contained in:
parent
6f01584607
commit
0336235c74
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 },
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 ??=
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
|
|
|
@ -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 };
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user