mirror of
https://github.com/nasa/openmct.git
synced 2025-06-13 12:48:14 +00:00
[API] Move type toward a newer API
This commit is contained in:
@ -31,10 +31,15 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
require(['main'], function (mct) {
|
require(['main'], function (mct) {
|
||||||
require([
|
require([
|
||||||
|
'./tutorials/todo/todo',
|
||||||
|
'./tutorials/todo/bundle',
|
||||||
'./example/imagery/bundle',
|
'./example/imagery/bundle',
|
||||||
'./example/eventGenerator/bundle',
|
'./example/eventGenerator/bundle',
|
||||||
'./example/generator/bundle'
|
'./example/generator/bundle'
|
||||||
], mct.start.bind(mct));
|
], function (todoPlugin) {
|
||||||
|
todoPlugin(mct);
|
||||||
|
mct.start();
|
||||||
|
})
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<link rel="stylesheet" href="platform/commonUI/general/res/css/startup-base.css">
|
<link rel="stylesheet" href="platform/commonUI/general/res/css/startup-base.css">
|
||||||
|
20
src/MCT.js
20
src/MCT.js
@ -1,11 +1,29 @@
|
|||||||
define(['EventEmitter'], function (EventEmitter) {
|
define([
|
||||||
|
'EventEmitter',
|
||||||
|
'legacyRegistry',
|
||||||
|
'./api/api'
|
||||||
|
], function (EventEmitter, legacyRegistry, api) {
|
||||||
function MCT() {
|
function MCT() {
|
||||||
EventEmitter.call(this);
|
EventEmitter.call(this);
|
||||||
|
this.legacyBundle = { extensions: {} };
|
||||||
}
|
}
|
||||||
|
|
||||||
MCT.prototype = Object.create(EventEmitter.prototype);
|
MCT.prototype = Object.create(EventEmitter.prototype);
|
||||||
|
|
||||||
|
Object.keys(api).forEach(function (k) {
|
||||||
|
MCT.prototype[k] = api[k];
|
||||||
|
});
|
||||||
|
|
||||||
|
MCT.prototype.type = function (key, type) {
|
||||||
|
var legacyDef = type.toLegacyDefinition();
|
||||||
|
legacyDef.key = key;
|
||||||
|
this.legacyBundle.extensions.types =
|
||||||
|
this.legacyBundle.extensions.types || [];
|
||||||
|
this.legacyBundle.extensions.types.push(legacyDef);
|
||||||
|
};
|
||||||
|
|
||||||
MCT.prototype.start = function () {
|
MCT.prototype.start = function () {
|
||||||
|
legacyRegistry.register('adapter', this.legacyBundle);
|
||||||
this.emit('start');
|
this.emit('start');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
43
src/api/Type.js
Normal file
43
src/api/Type.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
define(function () {
|
||||||
|
/**
|
||||||
|
* @typedef TypeDefinition
|
||||||
|
* @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)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {TypeDefinition} definition
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
function Type(definition) {
|
||||||
|
this.definition = definition;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a definition for this type that can be registered using the
|
||||||
|
* legacy bundle format.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
Type.prototype.toLegacyDefinition = function () {
|
||||||
|
var def = {};
|
||||||
|
def.name = this.definition.metadata.label;
|
||||||
|
def.glyph = this.definition.metadata.glyph;
|
||||||
|
def.description = this.definition.metadata.description;
|
||||||
|
|
||||||
|
if (this.definition.initialize) {
|
||||||
|
def.model = {};
|
||||||
|
this.definition.initialize(def.model);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.definition.creatable) {
|
||||||
|
def.features = ['creation'];
|
||||||
|
}
|
||||||
|
return def;
|
||||||
|
};
|
||||||
|
|
||||||
|
return Type;
|
||||||
|
});
|
9
src/api/api.js
Normal file
9
src/api/api.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
define([
|
||||||
|
'./Type'
|
||||||
|
], function (
|
||||||
|
Type
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
Type: Type
|
||||||
|
};
|
||||||
|
});
|
Reference in New Issue
Block a user