Skip to content
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

fix(formatting): Date/RegExp values output by formatComplexDataStructure #250

Merged

Conversation

lahmatiy
Copy link
Contributor

@lahmatiy lahmatiy commented Nov 13, 2017

sortobject breaks output of Date and RegExp values, since makes an object copy of those values instead returning as is. Therefore, formatComplexDataStructure for following object

{
    date: new Date('2017-11-13T00:00:00.000Z'),
    regexp: /test/g
}

outputs

{
    date: {},
    regexp: {}
}

We can fix sortobject by sending a PR. But its implementation is too verbose for such simple task. So I decided to add an own implementation of sortObject instead of patching sortobject. This also helps keep things simpler and allows adjust behaviour if needed.

@ghost
Copy link

ghost commented Nov 13, 2017

There were the following issues with this Pull Request

  • Commit: dd22fc5
    • ✖ message may not be empty
    • ✖ type may not be empty

@ghost
Copy link

ghost commented Nov 13, 2017

There were the following issues with this Pull Request

  • Commit: dd22fc5
    • ✖ message may not be empty
    • ✖ type may not be empty
  • Commit: 9dbbec8
    • ✖ message may not be empty
    • ✖ type may not be empty

@lahmatiy lahmatiy force-pushed the fix-format-complex-data-structure branch from 9dbbec8 to a9e01e3 Compare November 13, 2017 23:25
@lahmatiy lahmatiy changed the title Replace sortobject for own implementation Fix Date/RegExp values output in formatComplexDataStructure by replacing sortobject for own implementation Nov 13, 2017
@lahmatiy lahmatiy changed the title Fix Date/RegExp values output in formatComplexDataStructure by replacing sortobject for own implementation fix(formatting): Date/RegExp values output by formatComplexDataStructure Nov 13, 2017
Copy link
Collaborator

@armandabric armandabric left a comment

Choose a reason for hiding this comment

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

Good job 👍 We will definitely merge this!

Do not forget to rebase the PR too 😃

@@ -86,4 +86,20 @@ describe('formatComplexDataStructure', () => {
it('should format an empty array', () => {
expect(formatComplexDataStructure([], false, 0, options)).toEqual('[]');
});

it('should format an object that contains a date', () => {
Copy link
Collaborator

@armandabric armandabric Nov 14, 2017

Choose a reason for hiding this comment

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

I guess theses tests are more related to sortObject behavior than the formatComplexDataStructure one. We should move then in the sortObject.spec.js file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sortObject has its own test for that. I think left it here since not only sortObject is used to process objects and other logic can break things too.


import sortObject from './sortObject';

describe('formatComplexDataStructure', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oups! Should be describe('sortObject', () => {

c: date,
});
});
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add a test that validate that sortObject could be directly call with array sortObject([{...}, {...}]);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@lahmatiy lahmatiy force-pushed the fix-format-complex-data-structure branch from a9e01e3 to c9060a7 Compare November 14, 2017 17:23
@lahmatiy
Copy link
Contributor Author

Done :)

@armandabric armandabric merged commit 0387b72 into algolia:master Nov 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants