Skip to content

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.



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