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

Return a sorted copy from array.sort() #250

Merged
merged 2 commits into from
Feb 26, 2017

Conversation

gabrielgrant
Copy link
Contributor

Fixes #249

Note: sort() currently returns undefined when the observed property is undefined, while Ember's computed.sort() returns an empty array. Not sure if this difference is intended, I found it a bit surprising.

At the moment, it seems array/-utils.normalizeArray will accept a static default value, but I think we'd want to use a factory function that generates default values (new Array objects, in this case). Changing the normalizeArray API seems a bit outside the scope of this PR, so I haven't actually touched this, but have added a test for the current behavior (returning undefined) and a skipped test for the (in my mind) expected behavior (returning an empty Array).

Happy to open another issue/PR to address this if it's something you'd like changed.

@@ -0,0 +1,83 @@
import { sort } from 'ember-awesome-macros/array';
Copy link
Owner

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, no, totally missed those 🤦‍♂️ just saw the length tests in tests/unit/array and foolishly thought there weren't any for sort

Copy link
Contributor Author

@gabrielgrant gabrielgrant Feb 24, 2017

Choose a reason for hiding this comment

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

Would you like me to move the non-duplicate tests (the last three, I believe) into the existing integration test file? (they seemed a bit more like unit tests to me, but not sure how/where you're drawing the line?)

The composibility test was copied basically verbatim from length-test, and the other two are testing the specific functionality of this patch (ie they fail without the accompanying code change)

Copy link
Owner

Choose a reason for hiding this comment

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

The line I'm using is unit tests use mocking (I verify .sort() was called on my mock) and the integration tests use the real implementation more along the lines of a smoke test.

Copy link
Contributor Author

@gabrielgrant gabrielgrant Feb 25, 2017

Choose a reason for hiding this comment

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

ok, well in that case what i've written as unit tests are in fact integration tests...but half of what's currently in the integration tests file are unit tests :P

Edit : nvm, i was mis-reading -- they use stubs for the sort definitions, not the array's .sort()

I'll move mine over to the existing test file, and update the PR

Copy link
Contributor Author

@gabrielgrant gabrielgrant Feb 25, 2017

Choose a reason for hiding this comment

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

@kellyselden What are your thoughts on current behavior of returning undefined vs Ember.computed.sort behavior of returning [] when the source is undefined?

Copy link
Owner

Choose a reason for hiding this comment

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

This is an issue that most the macros have. I couldn't decide what the default value is if all the params are undefined, so most return undefined. I'm seeing that lodash returns empty arrays in most cases, so maybe all the macros need this change.

Copy link
Owner

Choose a reason for hiding this comment

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

Filed an issue for this #251

@gabrielgrant
Copy link
Contributor Author

ok, moved the tests from unit into the existing integration. If this looks good, happy to rebase out the extra commits

@kellyselden
Copy link
Owner

Looks great. Feel free to squash, or I can do it via github UI.

@gabrielgrant
Copy link
Contributor Author

Cool, killed the redundant test commits, should be ready to merge (squashing further if you want) afaics

@kellyselden kellyselden merged commit 109b091 into kellyselden:master Feb 26, 2017
@kellyselden
Copy link
Owner

Great work. Released v0.31.3.

@gabrielgrant
Copy link
Contributor Author

Sweet, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants