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

reduce number of components searched #149

Merged

Conversation

fivetanley
Copy link
Contributor

This commit has 2 goals:

  1. A small refactoring of the getValue method to split out the
    multiple/single value cases.
  2. Decrease the number of elements _getValue searches through if
    possible. Array.prototype.find stops iterating on the array when the
    callback returns truthy. options is an Ember.A which means it should
    polyfill the Array.prototype.find method.

Say you have an array like:

const values = [1, 2, 3];

If we're looking for the value 2, we only want to search the array two
times, because the number 2 is found on the second iteration.

This reduces the amount of work we have to do on larger arrays because
we can bail if the element is found early. While this doesn't matter
much on an array of 5, it can matter more with bigger arrays especially
since we're querying the DOM.

This commit has 2 goals:

1) A small refactoring of the getValue method to split out the
multiple/single value cases.
2) Decrease the number of elements `_getValue` searches through if
possible. `Array.prototype.find` stops iterating on the array when the
callback returns truthy. `options` is an `Ember.A` which means it should
polyfill the `Array.prototype.find` method.

Say you have an array like:

```javascript
const values = [1, 2, 3];
```

If we're looking for the value `2`, we only want to search the array two
times, because the number 2 is found on the second iteration.

This reduces the amount of work we have to do on larger arrays because
we can bail if the element is found early. While this doesn't matter
much on an array of 5, it can matter more with bigger arrays especially
since we're querying the DOM.
@Robdel12
Copy link
Collaborator

You da best @fivetanley. Thanks for fixing x-select up :p

@Robdel12 Robdel12 merged commit c575bf3 into adopted-ember-addons:master Sep 14, 2016
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