Add new options, generics, and unit tests for BaseCollection.

Review Request #12913 — Created March 23, 2023 and submitted — Latest diff uploaded

Information

Spina
master

Reviewers

BaseCollection (and Backbone.Collection) lacked some of the
capabilities available to models and views. It wasn't possible to
provide typed custom options, for example. There were also some mistakes
made with recent changes to specify model types.

This change introduces new generics when subclassing BaseCollection,
allowing an interface to be provided for custom options. This mixes into
an interface (now provided in our version of the Backbone typings) of
standard options for the class. The combined results are passed to
preinitialize, initialize, and constructor. This follows the same
patterns used in Model and View.

Typings for the model on the collection are now fixed. The attempt at
defining and using a Subclass<T> didn't work in practice. We only
needed Class<T>.

The url static attribute can now be a function, which will be called
properly with the instance as this.

The default model type for collections is also now Backbone.Model
instead of BaseModel, to provide better backwards-compatibility.

Unit tests have been added to test all static attribute/function
behavior. Since our testing uses TypeScript, the type-related issues
were also caught by tests.

Unit tests pass.

Commits

Files