Add new options, generics, and unit tests for BaseCollection.
Review Request #12913 — Created March 23, 2023 and submitted — Latest diff uploaded
BaseCollection
(andBackbone.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
, andconstructor
. This follows the same
patterns used inModel
andView
.Typings for the model on the collection are now fixed. The attempt at
defining and using aSubclass<T>
didn't work in practice. We only
neededClass<T>
.The
url
static attribute can now be a function, which will be called
properly with the instance asthis
.The default model type for collections is also now
Backbone.Model
instead ofBaseModel
, 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.