HomePhabricator

Harden generic .addItems() methods in GroupElement and subclasses

Description

Harden generic .addItems() methods in GroupElement and subclasses

This change will make callers that call .addItems() with undefined or
null ignore the argument instead of failing. While I'm usually a fan
of the "garbage in, garbage out" rule I believe this is a valid
exception. Callers usually look like this:

config = config || {};
this.addItems( config.items );

There is nothing wrong with not providing items. This is not
unexpected.

Aditional benefits:

  • More consistent behavior. Some callers just checked if config.items exists, some checked if it's actually an array.
  • Many constructors ignored bad values in config.items because of the .isArray() check. In other words, we suppressed possibly relevant errors here.
  • No more change events when nothing changed.
  • Less code duplication.

Change-Id: Ib1241f93d214e8a7d2f757a120f84de3879575af

Details

Provenance
thiemowmdeAuthored on Dec 17 2021, 7:28 AM
Parents
rGOJU72e5114c6fd1: Merge "Optimize hot code paths in LabelElement class"
Branches
Unknown
Tags
Unknown
ChangeId
Ib1241f93d214e8a7d2f757a120f84de3879575af