RC Filters: Avoid unnecessary update events when clearing highlight
authorKosta Harlan <kosta@fastmail.com>
Fri, 29 Jun 2018 18:58:03 +0000 (14:58 -0400)
committerGergő Tisza <gtisza@wikimedia.org>
Mon, 2 Jul 2018 16:23:46 +0000 (16:23 +0000)
The strict equality check just below the lines added in this commit will fail
if the Item's highlightColor is null/undefined, and if the incoming parameter
is null. This situation happens when
mw.rcfilters.dm.ItemModel.prototype.clearHighlightColor is called when updating
the state from the query parameters. By returning early we can avoid emitting
update events for every filter item.

Bug: T198359
Change-Id: Ia3e5f333964545c7f33777be915389728c03eace

resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.ItemModel.js

index d1e40ca..fef5226 100644 (file)
                if ( !this.isHighlightSupported() ) {
                        return;
                }
+               // If the highlight color on the item and in the parameter is null/undefined, return early.
+               if ( !this.highlightColor && !highlightColor ) {
+                       return;
+               }
 
                if ( this.highlightColor !== highlightColor ) {
                        this.highlightColor = highlightColor;