-
Notifications
You must be signed in to change notification settings - Fork 27.4k
refact(ngOptions): major refactoring... #10639
Conversation
would it be possible to split this into two commits, one that move things around and another that make the modifications? It would make it a lot easier to review the patch. One PR is ok and so is the order of the commits |
Not really. The original file (select.js) is so interwoven it was not really feasible to extract the ngOptions bits without doing a lot of the refactoring. I'll see what I can do... |
I guess I could combine these two files into one and then split them in a subsequent commit? |
the issue with the current patch is that is very hard to know what actually changed and what was only moved. Whatever makes this easy, works for me |
Well pretty much everything that was related to ngOptions changed :-) |
d4b1762
to
6f38132
Compare
@lgalfaso - How's that? |
6f38132
to
1658c39
Compare
what will happen if the same option value shows up several times? This can happen when the two options are in different option groups |
Good question, I have to check the previous implementation but I think it didn't support multiple options with the same value either, |
Even if the previous implementation did support it, is that really a valid requirement? How would you even select the correct item in the list the next time they view that page? you'd have to 'track by' group and value. |
@jayoungers - thanks for commenting. I agree that this requirement would be tricky. You could certainly create a |
I was thinking when there is no |
@lgalfaso - so you are referring to the standard |
@petebacondarwin ok, makes sense |
26c769d
to
f87382e
Compare
This looks like a great refactoring, because now we could even put ngOptions inside another module. Three general observations:
|
Awesome bit of review @gkalpak - thank you. I will address those issues over the weekend. |
8d9dfd6
to
78b9344
Compare
…ns are loaded async **Major reworking of select and ngOptions**: * The `SelectController` is now used as an abstraction for the `select` and `ngOptions` directives to override to get their desired behaviour * The `select` directive is completely oblivious to the ngOptions directive now - the `ngOptions` directive could be deleted without having to make any changes to the `select` directive. * Select related directives (single/multiple/ngOptions) can provide specific versions of `SelectController.writeValue` and `SelectController.readValue`, which are responsible for getting the `$viewValue` in or out of the actual `<select>` element and its `<option>` children. BREAKING CHANGE: When using `ngOptions`: the directive applies a surrogate key as the value of the `<option>` element. This commit changes the actual string used as the surrogate key. We now store a string that is computed by calling `hashKey` on the item in the options collection; previously it was the index or key of the item in the collection. (This is in keeping with the way that the unknown option value is represented in the select directive.) Before you might have seen: ``` <select ng-model="x" ng-option="i in items"> <option value="1">a</option> <option value="2">b</option> <option value="3">c</option> <option value="4">d</option> </select> ``` Now it will be something like: ``` <select ng-model="x" ng-option="i in items"> <option value="string:a">a</option> <option value="string:b">b</option> <option value="string:c">c</option> <option value="string:d">d</option> </select> ``` If your application code relied on this value, which it shouldn't, then you will need to modify your application to accommodate this. You may find that you can use the `track by` feaure of `ngOptions` as this provides the ability to specify the key that is stored. Closes angular#9714 Closes angular#10639
ede182e
to
c77b006
Compare
6c0b011
to
aa0064c
Compare
…ns are loaded async **Major reworking of select and ngOptions**: * The `SelectController` is now used as an abstraction for the `select` and `ngOptions` directives to override to get their desired behaviour * The `select` directive is completely oblivious to the ngOptions directive now - the `ngOptions` directive could be deleted without having to make any changes to the `select` directive. * Select related directives (single/multiple/ngOptions) can provide specific versions of `SelectController.writeValue` and `SelectController.readValue`, which are responsible for getting the `$viewValue` in or out of the actual `<select>` element and its `<option>` children. BREAKING CHANGE: When using `ngOptions`: the directive applies a surrogate key as the value of the `<option>` element. This commit changes the actual string used as the surrogate key. We now store a string that is computed by calling `hashKey` on the item in the options collection; previously it was the index or key of the item in the collection. (This is in keeping with the way that the unknown option value is represented in the select directive.) Before you might have seen: ``` <select ng-model="x" ng-option="i in items"> <option value="1">a</option> <option value="2">b</option> <option value="3">c</option> <option value="4">d</option> </select> ``` Now it will be something like: ``` <select ng-model="x" ng-option="i in items"> <option value="string:a">a</option> <option value="string:b">b</option> <option value="string:c">c</option> <option value="string:d">d</option> </select> ``` If your application code relied on this value, which it shouldn't, then you will need to modify your application to accommodate this. You may find that you can use the `track by` feaure of `ngOptions` as this provides the ability to specify the key that is stored. Closes angular#8019 Closes angular#9714 Closes angular#10639
aa0064c
to
4a9cd13
Compare
…ns are loaded async **Major reworking of select and ngOptions**: * The `SelectController` is now used as an abstraction for the `select` and `ngOptions` directives to override to get their desired behaviour * The `select` directive is completely oblivious to the ngOptions directive now - the `ngOptions` directive could be deleted without having to make any changes to the `select` directive. * Select related directives (single/multiple/ngOptions) can provide specific versions of `SelectController.writeValue` and `SelectController.readValue`, which are responsible for getting the `$viewValue` in or out of the actual `<select>` element and its `<option>` children. BREAKING CHANGE: When using `ngOptions`: the directive applies a surrogate key as the value of the `<option>` element. This commit changes the actual string used as the surrogate key. We now store a string that is computed by calling `hashKey` on the item in the options collection; previously it was the index or key of the item in the collection. (This is in keeping with the way that the unknown option value is represented in the select directive.) Before you might have seen: ``` <select ng-model="x" ng-option="i in items"> <option value="1">a</option> <option value="2">b</option> <option value="3">c</option> <option value="4">d</option> </select> ``` Now it will be something like: ``` <select ng-model="x" ng-option="i in items"> <option value="string:a">a</option> <option value="string:b">b</option> <option value="string:c">c</option> <option value="string:d">d</option> </select> ``` If your application code relied on this value, which it shouldn't, then you will need to modify your application to accommodate this. You may find that you can use the `track by` feaure of `ngOptions` as this provides the ability to specify the key that is stored. Closes angular#8019 Closes angular#9714 Closes angular#10639
LGTM, @petebacondarwin can you land this? |
…ns are loaded async **Major reworking of select and ngOptions**: * The `SelectController` is now used as an abstraction for the `select` and `ngOptions` directives to override to get their desired behaviour * The `select` directive is completely oblivious to the ngOptions directive now - the `ngOptions` directive could be deleted without having to make any changes to the `select` directive. * Select related directives (single/multiple/ngOptions) can provide specific versions of `SelectController.writeValue` and `SelectController.readValue`, which are responsible for getting the `$viewValue` in or out of the actual `<select>` element and its `<option>` children. BREAKING CHANGE: When using `ngOptions`: the directive applies a surrogate key as the value of the `<option>` element. This commit changes the actual string used as the surrogate key. We now store a string that is computed by calling `hashKey` on the item in the options collection; previously it was the index or key of the item in the collection. (This is in keeping with the way that the unknown option value is represented in the select directive.) Before you might have seen: ``` <select ng-model="x" ng-option="i in items"> <option value="1">a</option> <option value="2">b</option> <option value="3">c</option> <option value="4">d</option> </select> ``` Now it will be something like: ``` <select ng-model="x" ng-option="i in items"> <option value="string:a">a</option> <option value="string:b">b</option> <option value="string:c">c</option> <option value="string:d">d</option> </select> ``` If your application code relied on this value, which it shouldn't, then you will need to modify your application to accommodate this. You may find that you can use the `track by` feaure of `ngOptions` as this provides the ability to specify the key that is stored. BREAKING CHANGE: When iterating over an object's properties using the `(key, value) in obj` syntax the order of the elements used to be sorted alphabetically. This was an artificial attempt to create a deterministic ordering since browsers don't guarantee the order. But in practice this is not what people want and so this change iterates over properties in the order they are returned by Object.keys(obj), which is almost always the order in which the properties were defined. Closes angular#8019 Closes angular#9714 Closes angular#10639
Since select is not aware of ngOptions, it makes sense to move it into its own file for more easy maintenance.
…ns maps to null Closes angular#7605
Utilize the $watchDelegate on the watcher used to detect changes to the labels. Closes angular#10687 Closes angular#10694
Landing now. |
dbb0ab3
to
70e5015
Compare
Major reworking of select and ngOptions:
SelectController
is now used as an abstraction for theselect
andngOptions
directivesto override to get their desired behaviour
select
directive is completely oblivious to the ngOptions directive now - thengOptions
directive could be deleted without having to make any changes to the
select
directive.SelectController.writeValue
andSelectController.readValue
, which are responsible for gettingthe
$viewValue
in or out of the actual<select>
element and its<option>
children.BREAKING CHANGE:
When using
ngOptions
: the directive applies a surrogate key as the value of the<option>
element.This commit changes the actual string used as the surrogate key. We now store a string that is computed
by calling
hashKey
on the item in the options collection; previously it was the index or key of theitem in the collection.
Before you might have seen:
Now it will be something like:
If your application code relied on this value, which it shouldn't, then you will need to modify your
application to accommodate this. You may find that you can use the
track by
feaure ofngOptions
as this provides the ability to specify the key that is stored.
BREAKING CHANGE:
When iterating over an object's properties using the
(key, value) in obj
syntax the order of the elements used to be sorted alphabetically. This was an artificial attempt to create a deterministic ordering since browsers don't guarantee the order. But in practice this is not what people want and so this change iterates over properties in the order they are returned byObject.keys(obj)
, which is almost always the order in which the properties were defined.Closes #8019
Closes #9714
Closes #10531