Add accessors for common class attribute lookups.

Review Request #13552 — Created Feb. 18, 2024 and submitted — Latest diff uploaded

Information

Spina
master

Reviewers

Backbone's design allows for both static (unchanging, not ES6 static)
and dynamic (function-based) values for many class attributes. To safely
query these, callers are expected to access these attributes using
_.result(obj, 'attrname'), which doesn't feel natural with ES6
classes.

This change introduces accessors for these attributes. You can now fetch
myModel.getURL() or myView.getTagName(), for example, instead of
_.result(myModel, 'url') or _.result(myView, 'tagName').

These are type-safe as well.

Unit tests pass.

Diff Revision 1 (Latest)

Commits

First Last Summary ID Author
Add accessors for common class attribute lookups.
Backbone's design allows for both static (unchanging, not ES6 static) and dynamic (function-based) values for many class attributes. To safely query these, callers are expected to access these attributes using `_.result(obj, 'attrname')`, which doesn't feel natural with ES6 classes. This change introduces accessors for these attributes. You can now fetch `myModel.getURL()` or `myView.getTagName()`, for example, instead of `_.result(myModel, 'url')` or `_.result(myView, 'tagName')`. These are type-safe as well.
5c9ef77e7a1c80b17813f6aa5efbf98125e2df21 Christian Hammond
src/collection.ts
src/model.ts
src/view.ts
src/tests/baseCollectionTests.ts
src/tests/baseModelTests.ts
src/tests/baseViewTests.ts
Loading...