• 
      

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

    Review Request #12915 — Created March 23, 2023 and submitted

    Information

    Spina
    master

    Reviewers

    BaseRouter (and Backbone.Router) lacked some of the capabilities
    available to models and views. It wasn't possible to provide typed
    custom options, for example. Our typing also didn't allow for routes to
    be dynamically-constructed.

    This change introduces new generics when subclassing BaseRouter or
    Backbone.Router, 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 standard options have been updated to not require routes to be
    specified.

    The combined results are passed to preinitialize, initialize, and
    constructor. This follows the same patterns used in Model and
    View.

    The routes static attribute can now be a function, which returns the
    routes for an instance. This is run with the instance being passed as
    this.

    A new RoutesHash type has been exported. This maps to
    Backbone.RoutesHash, and is easier to reference without importing
    Backbone.

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

    Unit tests pass.

    Summary ID
    Add new options, generics, and unit tests for routers.
    `BaseRouter` (and `Backbone.Router`) lacked some of the capabilities available to models and views. It wasn't possible to provide typed custom options, for example. Our typing also didn't allow for routes to be dynamically-constructed. This change introduces new generics when subclassing `BaseRouter` or `Backbone.Router`, 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 standard options have been updated to not require `routes` to be specified. The combined results are passed to `preinitialize`, `initialize`, and `constructor`. This follows the same patterns used in `Model` and `View`. The `routes` static attribute can now be a function, which returns the routes for an instance. This is run with the instance being passed as `this`. A new `RoutesHash` type has been exported. This maps to `Backbone.RoutesHash`, and is easier to reference without importing Backbone. Unit tests have been addd to test all static attributes/fucntion behavior. Since our testing uses TypeScript, the type-related issues were also caught by tests.
    d9cc24606f180e19ce166dd8fe72247b6f8a8993
    chipx86
    david
    1. Ship It!
    2. 
        
    chipx86
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to master (242cac0)