js: Convert Object.assign({…}, …) to spread syntax.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2020-12-21 15:37:36 -08:00
parent 160cc5120a
commit 0c4239e387
7 changed files with 42 additions and 78 deletions

View File

@ -22,7 +22,7 @@ zrequire("hash_util");
const emoji = zrequire("emoji", "shared/js/emoji");
const pygments_data = zrequire("pygments_data", "generated/pygments_data.json");
const actual_pygments_data = Object.assign({}, pygments_data);
const actual_pygments_data = {...pygments_data};
const ct = zrequire("composebox_typeahead");
const th = zrequire("typeahead_helper");
const {LazySet} = zrequire("lazy_set");

View File

@ -102,15 +102,14 @@ exports.build_page = function () {
upgrade_text_for_wide_organization_logo:
page_params.upgrade_text_for_wide_organization_logo,
realm_default_external_accounts: page_params.realm_default_external_accounts,
admin_settings_label,
msg_edit_limit_dropdown_values: settings_config.msg_edit_limit_dropdown_values,
msg_delete_limit_dropdown_values: settings_config.msg_delete_limit_dropdown_values,
bot_creation_policy_values: settings_bots.bot_creation_policy_values,
email_address_visibility_values: settings_config.email_address_visibility_values,
...settings_org.get_organization_settings_options(),
};
options.admin_settings_label = admin_settings_label;
options.msg_edit_limit_dropdown_values = settings_config.msg_edit_limit_dropdown_values;
options.msg_delete_limit_dropdown_values = settings_config.msg_delete_limit_dropdown_values;
options.bot_creation_policy_values = settings_bots.bot_creation_policy_values;
options.email_address_visibility_values = settings_config.email_address_visibility_values;
Object.assign(options, settings_org.get_organization_settings_options());
if (options.realm_logo_source !== "D" && options.realm_night_logo_source === "D") {
// If no night mode logo is specified but a day mode one is,
// use the day mode one. See also similar code in realm_logo.js.

View File

@ -5,14 +5,12 @@ const render_dropdown_list = require("../templates/settings/dropdown_list.hbs");
const DropdownListWidget = function (opts) {
const init = () => {
// Run basic sanity checks on opts, and set up sane defaults.
opts = Object.assign(
{
null_value: null,
render_text: (item_name) => item_name,
on_update: () => {},
},
opts,
);
opts = {
null_value: null,
render_text: (item_name) => item_name,
on_update: () => {},
...opts,
};
opts.container_id = `${opts.widget_name}_widget`;
opts.value_id = `id_${opts.widget_name}`;
if (opts.value === undefined) {

View File

@ -412,13 +412,12 @@ function fetch_group_members(member_ids) {
return member_ids
.map((m) => people.get_by_user_id(m))
.filter((m) => m !== undefined)
.map((p) =>
Object.assign({}, p, {
user_circle_class: buddy_data.get_user_circle_class(p.user_id),
is_active: people.is_active_user_for_popover(p.user_id),
user_last_seen_time_status: buddy_data.user_last_seen_time_status(p.user_id),
}),
);
.map((p) => ({
...p,
user_circle_class: buddy_data.get_user_circle_class(p.user_id),
is_active: people.is_active_user_for_popover(p.user_id),
user_last_seen_time_status: buddy_data.user_last_seen_time_status(p.user_id),
}));
}
function sort_group_members(members) {

View File

@ -40,7 +40,7 @@ const INITIAL_STATE = {
query: "",
};
let state = Object.assign({}, INITIAL_STATE);
let state = {...INITIAL_STATE};
function adjust_font_sizing() {
$(".integration-lozenge")
@ -224,7 +224,7 @@ function hide_integration_show_catalog() {
}
function get_state_from_path() {
const result = Object.assign({}, INITIAL_STATE);
const result = {...INITIAL_STATE};
result.query = state.query;
const parts = path_parts();
@ -238,7 +238,7 @@ function get_state_from_path() {
}
function render(next_state) {
const previous_state = Object.assign({}, state);
const previous_state = {...state};
state = next_state;
if (previous_state.integration !== next_state.integration && next_state.integration !== null) {
@ -264,48 +264,27 @@ function render(next_state) {
function dispatch(action, payload) {
switch (action) {
case "CHANGE_CATEGORY":
render(
Object.assign({}, state, {
category: payload.category,
}),
);
render({...state, category: payload.category});
update_path();
break;
case "SHOW_INTEGRATION":
render(
Object.assign({}, state, {
integration: payload.integration,
}),
);
render({...state, integration: payload.integration});
update_path();
break;
case "HIDE_INTEGRATION":
render(
Object.assign({}, state, {
integration: null,
}),
);
render({...state, integration: null});
update_path();
break;
case "SHOW_CATEGORY":
render(
Object.assign({}, state, {
integration: null,
category: payload.category,
}),
);
render({...state, integration: null, category: payload.category});
update_path();
break;
case "UPDATE_QUERY":
render(
Object.assign({}, state, {
query: payload.query,
}),
);
render({...state, query: payload.query});
break;
case "LOAD_PATH":

View File

@ -596,13 +596,10 @@ exports.signup_notifications_stream_widget = null;
exports.init_dropdown_widgets = () => {
const streams = stream_data.get_streams_for_settings_page();
const notification_stream_options = {
data: streams.map((x) => {
const item = {
name: x.name,
value: x.stream_id.toString(),
};
return item;
}),
data: streams.map((x) => ({
name: x.name,
value: x.stream_id.toString(),
})),
on_update: () => {
exports.save_discard_widget_status_handler($("#org-notifications"));
},
@ -610,24 +607,16 @@ exports.init_dropdown_widgets = () => {
render_text: (x) => `#${x}`,
null_value: -1,
};
exports.notifications_stream_widget = dropdown_list_widget(
Object.assign(
{
widget_name: "realm_notifications_stream_id",
value: page_params.realm_notifications_stream_id,
},
notification_stream_options,
),
);
exports.signup_notifications_stream_widget = dropdown_list_widget(
Object.assign(
{
widget_name: "realm_signup_notifications_stream_id",
value: page_params.realm_signup_notifications_stream_id,
},
notification_stream_options,
),
);
exports.notifications_stream_widget = dropdown_list_widget({
widget_name: "realm_notifications_stream_id",
value: page_params.realm_notifications_stream_id,
...notification_stream_options,
});
exports.signup_notifications_stream_widget = dropdown_list_widget({
widget_name: "realm_signup_notifications_stream_id",
value: page_params.realm_signup_notifications_stream_id,
...notification_stream_options,
});
exports.default_code_language_widget = dropdown_list_widget({
widget_name: "realm_default_code_block_language",
data: Object.keys(pygments_data.langs).map((x) => ({

View File

@ -63,7 +63,7 @@ async function run() {
const messageBox = await page.$(messageSelector);
const messageGroup = (await messageBox.$x(".."))[0];
// Compute screenshot area, with some padding around the message group
const clip = Object.assign({}, await messageGroup.boundingBox());
const clip = {...(await messageGroup.boundingBox())};
clip.y -= 5;
clip.x -= 5;
clip.width += 10;