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

Update drag-coordinator.indexOf implementation to not use findIndex … #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ianpetzer
Copy link

…as hasMany does not support this

Copy link
Collaborator

@dgavey dgavey left a comment

Choose a reason for hiding this comment

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

Left some feedback, also I will need a test for your case of an array proxy as well before I can accept this PR. There are already some tests for ember-data in the test suite, you should be able to just build off of those.

@@ -5,9 +5,13 @@ import { isEqual } from '@ember/utils';


function indexOf(items, a) {
return items.findIndex(function (element) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ianpetzer Interesting that the findIndex didn't work in your case. I guess the hasMany proxy array doesn't implement this function.

return items.findIndex(function (element) {
return isEqual(element, a);
var returnIndex=null;
items.forEach(function(element, index) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ianpetzer This seems ok, but it doesn't break when it finds an item like the findIndex does. If you use a "for in" you can break sooner. That will make for more performant code.

https://stackoverflow.com/questions/2641347/short-circuit-array-foreach-like-calling-break

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