Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(select): update labels #9061

Closed
wants to merge 1 commit into from
Closed

Conversation

btford
Copy link
Contributor

@btford btford commented Sep 12, 2014

Closes #9025

@btford
Copy link
Contributor Author

btford commented Sep 12, 2014

I think that I can possibly implement this more efficiently but I wanted a proof of concept diff that wasn't totally insane.

if (values) {
var toDisplay = [];
for (var i = 0, ii = values.length; i < ii; i++) {
locals[valueName] = values[i];
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sure I'm just not seeing it, but where is valueName defined?

Copy link
Contributor

Choose a reason for hiding this comment

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

nevermind, apparently was searching for nameValue --- so what are we doing, registering a $watchCollection in the middle of setup, for a single option?

Copy link
Contributor

Choose a reason for hiding this comment

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

What this is doing is saying, every digest loop, build a new array of all the display names, which are generated from expressions, which usually rely upon the valueName. Then if this array changes then re-render.

It is rather heavy weight - if we could say that these expressions only ever depended upon the values in the ng-option expression then it could be much simpler.

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the goal here to update labels dynamically though? in which case the values wouldn't matter much.

I think we could do a better job by doing the work in a single watcher, but it would be hard to read/reason about (the select directive is already pretty hard to read and reason about)

@petebacondarwin
Copy link
Contributor

The trouble with this is that we then also have to do the same for things like groupByFn and so on.

Really what I'd like to do is believe that all these functions are only affected by the valuesFn and so we could just do

        scope.$watch(valuesFn, scheduleRendering, true);

instead of the

        scope.$watchCollection(valuesFn, scheduleRendering);

I tested this and it passes your test. It would of course fail if the displayFn et al also relied on some input outside of the values array.

@caitp
Copy link
Contributor

caitp commented Sep 12, 2014

we don't have a benchmark for <select> yet, afaik (it is possible that I'm wrong) --- the second watchCollection may be quicker than using object equality

@petebacondarwin
Copy link
Contributor

The second watchCollection is still in there with @btford's fix. What my suggestion would get rid of is @btford's new watchCollection

@btford
Copy link
Contributor Author

btford commented Sep 12, 2014

We're still better off than re-rendering on each digest, no?

Is this worth implementing a benchmark for?

@jeffbcross
Copy link
Contributor

@btford was this closed by 4627410?

@jeffbcross jeffbcross closed this Sep 18, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Select options won't update after changing scope's variable
5 participants