Consinder converting ActionsResult from a class to a plain object + typedef
Categories
(Firefox :: Address Bar, task)
Tracking
()
People
(Reporter: dao, Unassigned)
References
(Blocks 1 open bug)
Details
(Whiteboard: [sng][mcab-hnt])
Attachments
(1 file)
|
7.55 KB,
patch
|
Details | Diff | Splinter Review |
Follow-up to bug 2052554 (D310306), addressing review comment https://phabricator.services.mozilla.com/D310306#10767851.
ActionsResult (browser/components/urlbar/ActionsProvider.sys.mjs) has no methods and its instances are never deserialized, so modeling it as a class is confusing. mbeier suggested using a plain object and converting the class definition to a TypeScript typedef.
Proposed change:
- Replace the
ActionsResultclass with@typedef {object} ActionsResult--providerNameandkeyrequired,l10nId/l10nArgs/icon/dataset/engineoptional. - Have the producers (
ActionsProviderTabGroups,ActionsProviderQuickActions,ActionsProviderContextualSearch) build plain object literals typed via/** @type {ActionsResult} */with a JSDoc@import, dropping the runtimeimport.
Required-ness is then enforced statically by tsc (the urlbar tsconfig.json has checkJs + strict), replacing the constructor's runtime throw.
Tradeoff: the class currently calls Object.freeze(this) so each result is read-only (matching the original getter-only fields). A plain object literal is mutable, so this conversion drops that read-only guarantee. In practice the results are built once and only read, so it's likely fine, but if immutability is still wanted it can be reinstated by freezing the literal.
| Reporter | ||
Updated•7 days ago
|
Updated•7 days ago
|
Description
•