Add options for installing and merging class attributes.

Review Request #12907 — Created March 22, 2023 and submitted

Information

Spina
master

Reviewers

This introduces some important new options for Spina, designed to fix
problems encountered as we ported more class hierarchies from Backbone
to Spina.

ES6 classes have static attributes (which must be accessed on the class
constructor name) and instance attributes (which are only created when a
class is instantiated). What's missing are attributes that live on the
protocol (more akin to Python class attributes), which are what Backbone
really expects.

The recommendation is now to use static attributes. Spina now provides a
prototypeAttrs option for classes that are used to specify static
attributes (like events, defaults,tagName`, etc.) that must be made
available on the prototype. On class preparation, getters/setters will
be injected on the prototype to wrap the static attributes.

To aid in keeping attributes manageable, there's also a new
automergedAttrs option that can be defined on a class. This is used by
the class and any subclasses to merge together attributes containing
keys. For example, if a parent class and subclass both define events,
and this is in some base class's automergedAttrs, then the two will be
combined, reducing the chances of missing entries.

skipAutomergedAttrs can be used by a subclass to turn this behavior
off for select attributes, or all attributes.

These will be enabled soon for the built-in classes, and consumers can
use these to help transition to static-only attributes and to refine
class architectures.

Tested these new options in Review Board when converting classes to
Spina. Verified that specified attributes would merge and were
accessible on the prototype.

Summary ID
Add options for installing and merging class attributes.
This introduces some important new options for Spina, designed to fix problems encountered as we ported more class hierarchies from Backbone to Spina. ES6 classes have static attributes (which must be accessed on the class constructor name) and instance attributes (which are only created when a class is instantiated). What's missing are attributes that live on the protocol (more akin to Python class attributes), which are what Backbone really expects. The recommendation is now to use static attributes. Spina now provides a `prototypeAttrs` option for classes that are used to specify static attributes (like `events`, `defaults, `tagName`, etc.) that must be made available on the prototype. On class preparation, getters/setters will be injected on the prototype to wrap the static attributes. To aid in keeping attributes manageable, there's also a new `automergedAttrs` option that can be defined on a class. This is used by the class and any subclasses to merge together attributes containing keys. For example, if a parent class and subclass both define `events`, and this is in some base class's `automergedAttrs`, then the two will be combined, reducing the chances of missing entries. `skipAutomergedAttrs` can be used by a subclass to turn this behavior off for select attributes, or all attributes. These will be enabled soon for the built-in classes, and consumers can use these to help transition to static-only attributes and to refine class architectures.
fd14ec673e8e58112132e1723aa64859c3af6796
Description From Last Updated

Typo: merged -> merge.

daviddavid
david
  1. 
      
  2. src/objects.ts (Diff revision 1)
     
     
    Show all issues

    Typo: merged -> merge.

  3. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to master (1a5816b)
Loading...