fix(core): `QueryList` does not fire changes if the underlying list did not change. #40091
Conversation
77480e0
to
f02babb
2cd900f
to
266fa09
|
Overall this looks good, thanks for debugging this. Could you instead consider using the native Array#flat as this would simplify the code and in fact remove bulk of it. We'll then also need to add
to just so that we don't break on IE11 (the flat-map addition is not required by this change, but we might as well add it for future use). If we target this fix for |
|
LGTM (from code perspective), thanks for the fix @mhevery I was also thinking of using |
|
@IgorMinar |
29aa5b4
to
278dbce
| (this.changes as EventEmitter<any>).complete(); | ||
| (this.changes as EventEmitter<any>).unsubscribe(); |
AndrewKushnir
Dec 15, 2020
Contributor
We should probably do that for both _changesDeprecated and _changesStrict event emitters (in case both emitters were used in an app).
We should probably do that for both _changesDeprecated and _changesStrict event emitters (in case both emitters were used in an app).
| (this as {length: number}).length = this._results.length; | ||
| (this as {last: T}).last = this._results[this.length - 1]; | ||
| (this as {first: T}).first = this._results[0]; |
AndrewKushnir
Dec 15, 2020
Contributor
This is outside of the context of this PR, but it feels like these fields should be just getters on the QueryList class (so setting their values would not be required) and that should also help with typings above.
This is outside of the context of this PR, but it feels like these fields should be just getters on the QueryList class (so setting their values would not be required) and that should also help with typings above.
|
FYI, started global presubmit. |
|
I'd personally mark this for minor and not patch, since it introduces new API. |
| @@ -135,28 +169,36 @@ export class QueryList<T> implements Iterable<T> { | |||
| * occurs. | |||
| * | |||
| * @param resultsTree The query results to store | |||
| * @returns `true` only if the new `resultTree` resulted in a different query set. | |||
| * @internal | |||
JoostK
Dec 15, 2020
Member
Although this is marked @internal, it still shows up in the public api. As this is targeting patch I don't think we can/should hide this method in a patch release.
Although this is marked @internal, it still shows up in the public api. As this is targeting patch I don't think we can/should hide this method in a patch release.
mhevery
Dec 15, 2020
Author
Member
This is an internal method which should never be called by anyone. I can take it out if you feel strongly about it.
This is an internal method which should never be called by anyone. I can take it out if you feel strongly about it.
JoostK
Dec 15, 2020
Member
So I'm fine with marking it internal, it's just that doing so could break projects who call this method manually. So we may need to go through a deprecation period.
So I'm fine with marking it internal, it's just that doing so could break projects who call this method manually. So we may need to go through a deprecation period.
|
Global presubmit #2 (using Ivy). |
|
LGTM Reviewed-for: public-api |
6355a35
to
625551f
|
as discussed on slack, let's go with the |
6ff6cac
to
acf73d7
|
Thanks for the fix @mhevery |
...ler_compliance/components_and_directives/queries/static_content_query.js
Outdated
Show resolved
Hide resolved
|
You can preview 1d4e830 at https://pr40091-1d4e830.ngbuilds.io/. |
|
I like the new api name |
acf73d7
to
77eb52b
|
You can preview 77eb52b at https://pr40091-77eb52b.ngbuilds.io/. |
77eb52b
to
847658a
|
You can preview 847658a at https://pr40091-847658a.ngbuilds.io/. |
…id not change. Previous implementation would fire changes `QueryList.changes.subscribe` even if underlying list did not change. Such situation can arise if a `LView` is inserted or removed, causing `QueryList` to recompute, but the recompute results in the same exact `QueryList` result. In such a case we don't want to fire a change event (as there is no change.)
Because the query now has `flags` which specify the mode, the static query instruction can now be remove. It is simply normal query with `static` flag.
|
|
||
| none = 0, |
AndrewKushnir
Jan 11, 2021
Contributor
Small indentation update (rm line before none, add one after):
Suggested change
none = 0,
none = 0,
Small indentation update (rm line before none, add one after):
| none = 0, | |
| none = 0, | |
mhevery
Jan 11, 2021
Author
Member
Why line after? I think it is easier to read. Other places have line breaks like that as well.
Why line after? I think it is easier to read. Other places have line breaks like that as well.
AndrewKushnir
Jan 11, 2021
Contributor
It just looks like the comment is not "attached" to the none = 0 string (since there is a line in between a comment and an expression).
It just looks like the comment is not "attached" to the none = 0 string (since there is a line in between a comment and an expression).
mhevery
Jan 11, 2021
Author
Member
yes, that one (break between comment and declaration) I removed. But you are suggesting to remove the empty line after. That one I think should stay.
yes, that one (break between comment and declaration) I removed. But you are suggesting to remove the empty line after. That one I think should stay.
847658a
to
c469e9a
|
You can preview c469e9a at https://pr40091-c469e9a.ngbuilds.io/. |
c469e9a
to
9c15a80
Previous implementation would fire changes
QueryList.changes.subscribeeven if underlying list did not change. Such situation can arise if a
LViewis inserted or removed, causingQueryListto recompute, butthe recompute results in the same exact
QueryListresult. In sucha case we don't want to fire a change event (as there is no change.)
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information