mirror of
https://github.com/nasa/openmct.git
synced 2025-06-14 13:18:15 +00:00
[API] Propose registering instances
WTD-1237
This commit is contained in:
@ -751,3 +751,36 @@ JSDoc.)
|
|||||||
### Detriments
|
### Detriments
|
||||||
|
|
||||||
* Increases documentation burden.
|
* Increases documentation burden.
|
||||||
|
|
||||||
|
## Register Extensions as Instances instead of Constructors
|
||||||
|
|
||||||
|
Register extensions as object instances instead of constructors.
|
||||||
|
This allows for API flexibility w.r.t. constructor signatures
|
||||||
|
(and avoids the need for partial constructors) and additionally
|
||||||
|
makes it easier to provide platform implementations of extensions
|
||||||
|
that can be used, subclassed, etc.
|
||||||
|
|
||||||
|
For instance, instead of taking an `ActionContext` in its
|
||||||
|
constructor, an `Action` would be instantiated once and would
|
||||||
|
accept appropriate arguments to its methods:
|
||||||
|
|
||||||
|
```js
|
||||||
|
function SomeAction {
|
||||||
|
}
|
||||||
|
SomeAction.prototype.canHandle = function (actionContext) {
|
||||||
|
// Check if we can handle this context
|
||||||
|
};
|
||||||
|
SomeAction.prototype.perform = function (actionContext) {
|
||||||
|
// Perform this action, in this context
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### Benefits
|
||||||
|
|
||||||
|
* Reduces scope of interfaces to understand (don't need to know
|
||||||
|
what constructor signature to provide for compatibility.)
|
||||||
|
|
||||||
|
### Detriments
|
||||||
|
|
||||||
|
* Requires refactoring of various types; may result in some
|
||||||
|
awkward APIs or extra factory interfaces.
|
||||||
|
Reference in New Issue
Block a user