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 emoji = zrequire("emoji", "shared/js/emoji");
const pygments_data = zrequire("pygments_data", "generated/pygments_data.json"); 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 ct = zrequire("composebox_typeahead");
const th = zrequire("typeahead_helper"); const th = zrequire("typeahead_helper");
const {LazySet} = zrequire("lazy_set"); const {LazySet} = zrequire("lazy_set");

View File

@ -102,15 +102,14 @@ exports.build_page = function () {
upgrade_text_for_wide_organization_logo: upgrade_text_for_wide_organization_logo:
page_params.upgrade_text_for_wide_organization_logo, page_params.upgrade_text_for_wide_organization_logo,
realm_default_external_accounts: page_params.realm_default_external_accounts, 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 (options.realm_logo_source !== "D" && options.realm_night_logo_source === "D") {
// If no night mode logo is specified but a day mode one is, // 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. // 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 DropdownListWidget = function (opts) {
const init = () => { const init = () => {
// Run basic sanity checks on opts, and set up sane defaults. // Run basic sanity checks on opts, and set up sane defaults.
opts = Object.assign( opts = {
{ null_value: null,
null_value: null, render_text: (item_name) => item_name,
render_text: (item_name) => item_name, on_update: () => {},
on_update: () => {}, ...opts,
}, };
opts,
);
opts.container_id = `${opts.widget_name}_widget`; opts.container_id = `${opts.widget_name}_widget`;
opts.value_id = `id_${opts.widget_name}`; opts.value_id = `id_${opts.widget_name}`;
if (opts.value === undefined) { if (opts.value === undefined) {

View File

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

View File

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

View File

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

View File

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