[API] Simplify type registration

https://github.com/nasa/openmct/pull/1302#discussion_r85417042
This commit is contained in:
Victor Woeltjen 2016-10-27 15:30:34 -07:00
parent 12333f3417
commit 9a0fcc045c
4 changed files with 16 additions and 17 deletions

2
API.md
View File

@ -71,7 +71,7 @@ Custom types may be registered via
[`openmct.types`]{@link module:openmct.MCT#types}: [`openmct.types`]{@link module:openmct.MCT#types}:
``` ```
openmct.types.addType('my-type', new openmct.Type({ openmct.types.addType('my-type', {
label: "My Type", label: "My Type",
description: "This is a type that I added!", description: "This is a type that I added!",
creatable: true creatable: true

View File

@ -21,7 +21,6 @@
*****************************************************************************/ *****************************************************************************/
define([ define([
'./Type',
'./TimeConductor', './TimeConductor',
'./objects/ObjectAPI', './objects/ObjectAPI',
'./composition/CompositionAPI', './composition/CompositionAPI',
@ -30,7 +29,6 @@ define([
'./ui/GestureAPI', './ui/GestureAPI',
'./telemetry/TelemetryAPI' './telemetry/TelemetryAPI'
], function ( ], function (
Type,
TimeConductor, TimeConductor,
ObjectAPI, ObjectAPI,
CompositionAPI, CompositionAPI,
@ -40,7 +38,6 @@ define([
TelemetryAPI TelemetryAPI
) { ) {
return { return {
Type: Type,
TimeConductor: TimeConductor, TimeConductor: TimeConductor,
ObjectAPI: ObjectAPI, ObjectAPI: ObjectAPI,
CompositionAPI: CompositionAPI, CompositionAPI: CompositionAPI,

View File

@ -21,21 +21,12 @@
*****************************************************************************/ *****************************************************************************/
define(function () { define(function () {
/**
* @typedef TypeDefinition
* @memberof module:openmct.Type~
* @property {Metadata} metadata displayable metadata about this type
* @property {function (object)} [initialize] a function which initializes
* the model for new domain objects of this type
* @property {boolean} [creatable] true if users should be allowed to
* create this type (default: false)
*/
/** /**
* A Type describes a kind of domain object that may appear or be * A Type describes a kind of domain object that may appear or be
* created within Open MCT. * created within Open MCT.
* *
* @param {module:opemct.Type~TypeDefinition} definition * @param {module:opemct.TypeRegistry~TypeDefinition} definition
* @class Type * @class Type
* @memberof module:openmct * @memberof module:openmct
*/ */

View File

@ -20,7 +20,18 @@
* at runtime from the About dialog for additional information. * at runtime from the About dialog for additional information.
*****************************************************************************/ *****************************************************************************/
define([], function () { define(['./Type'], function (Type) {
/**
* @typedef TypeDefinition
* @memberof module:openmct.TypeRegistry~
* @property {string} label the name for this type of object
* @property {string} description a longer-form description of this type
* @property {function (object)} [initialize] a function which initializes
* the model for new domain objects of this type
* @property {boolean} [creatable] true if users should be allowed to
* create this type (default: false)
* @property {string} [cssclass] the CSS class to apply for icons
*/
/** /**
* A TypeRegistry maintains the definitions for different types * A TypeRegistry maintains the definitions for different types
@ -40,8 +51,8 @@ define([], function () {
* @method addType * @method addType
* @memberof module:openmct.TypeRegistry# * @memberof module:openmct.TypeRegistry#
*/ */
TypeRegistry.prototype.addType = function (typeKey, type) { TypeRegistry.prototype.addType = function (typeKey, typeDef) {
this.types[typeKey] = type; this.types[typeKey] = new Type(typeDef);
}; };
/** /**