Skip to content

chore: change Object.keys to Object.entries #1180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 14, 2020

Conversation

trivikr
Copy link
Member

@trivikr trivikr commented May 14, 2020

Issue #, if available:
N/A

Description of changes:

  • change Object.keys to Object.entries so that object doesn't have to be called in arrow function
  • also added type-checks for accumulators
  • also used destructuring assignment inside reduce

serializer

  • Before
const serializeAws_restJson1_1FilterCriteriaMap = (
  input: { [key: string]: Criterion },
  context: __SerdeContext
): any => {
  return Object.keys(input).reduce((acc: any, key: string) => {
    acc[key] = serializeAws_restJson1_1Criterion(input[key], context);
    return acc;
  }, {});
};
  • After
const serializeAws_restJson1_1FilterCriteriaMap = (
  input: { [key: string]: Criterion },
  context: __SerdeContext
): any => {
  return Object.entries(input).reduce(
    (acc: { [key: string]: Criterion }, [key, value]: [string, any]) => ({
      ...acc,
      [key]: serializeAws_restJson1_1Criterion(value, context)
    }),
    {}
  );
};

deserializer

  • Before
const deserializeAws_restJson1_1ConditionKeyMap = (
  output: any,
  context: __SerdeContext
): { [key: string]: string } => {
  return Object.keys(output).reduce((acc: any, key: string) => {
    acc[key] = output[key];
    return acc;
  }, {});
};
  • After
const deserializeAws_restJson1_1ConditionKeyMap = (
  output: any,
  context: __SerdeContext
): { [key: string]: string } => {
  return Object.entries(output).reduce(
    (acc: { [key: string]: string }, [key, value]: [string, any]) => ({
      ...acc,
      [key]: value
    }),
    {}
  );
};

buildFormUrlencodedString

  • Before
const buildFormUrlencodedString = (entries: any): string =>
  Object.keys(entries)
    .map(
      key =>
      ([key, value]) =>
        __extendedEncodeURIComponent(key) +
        "=" +
        __extendedEncodeURIComponent(entries[key])
    )
    .join("&");
  • After
const buildFormUrlencodedString = (formEntries: {
  [key: string]: string;
}): string =>
  Object.entries(formEntries)
    .map(
      ([key, value]) =>
        __extendedEncodeURIComponent(key) +
        "=" +
        __extendedEncodeURIComponent(value)
    )
    .join("&");

memberEntries

  • Before
    Object.keys(memberEntries).forEach(key => {
      const loc = `ScalingParameters.${key}`;
      entries[loc] = memberEntries[key];
    });
    Object.keys(memberEntries).forEach(key => {
      entries[`member.${counter}.${key}`] = memberEntries[key];
  • After
    Object.entries(memberEntries).forEach(([key, value]) => {
      const loc = `ScalingParameters.${key}`;
      entries[loc] = value;
    });
    Object.entries(memberEntries).forEach(([key, value]) => {
      entries[`member.${counter}.${key}`] = value;
    });

return statements in some deserialize functions

  • Before
  const key = Object.keys(output)[0];
  return { $unknown: [key, output[key]] };
  • After
  return { $unknown: Object.entries(output)[0] };

Verified that integration tests are successful:

$ AWS_PROFILE=<profile> yarn test:integration                                                                                         
yarn run v1.22.4
$ cucumber-js --fail-fast
.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

153 scenarios (153 passed)
534 steps (534 passed)
0m56.560s
Done in 59.43s.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@aws-sdk-js-automation
Copy link

AWS CodeBuild CI Report

  • CodeBuild project: sdk-staging-test
  • Commit ID: 30a51f6
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

@alexforsyth alexforsyth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@trivikr trivikr merged commit 99ec3d1 into aws:master May 14, 2020
@trivikr trivikr deleted the change-Object-keys-to-entries branch May 14, 2020 18:01
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants