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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions addon/services/drag-coordinator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 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

if (isEqual(element, a)) {
returnIndex=index;
}
});
return returnIndex;
}

function swapInPlace(items, a, b) {
Expand Down