mirror of
https://github.com/nasa/openmct.git
synced 2025-06-13 12:48:14 +00:00
[API] Wire in ObjectAPI appropriately
This commit is contained in:
@ -60,7 +60,7 @@ define([
|
|||||||
this.legacyBundle = { extensions: {
|
this.legacyBundle = { extensions: {
|
||||||
services: [
|
services: [
|
||||||
{
|
{
|
||||||
key: "mct",
|
key: "openmct",
|
||||||
implementation: function () {
|
implementation: function () {
|
||||||
return this;
|
return this;
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
|
@ -43,7 +43,7 @@ define([
|
|||||||
implementation: MCTView,
|
implementation: MCTView,
|
||||||
depends: [
|
depends: [
|
||||||
"newViews[]",
|
"newViews[]",
|
||||||
"mct"
|
"openmct"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -72,14 +72,14 @@ define([
|
|||||||
type: "decorator",
|
type: "decorator",
|
||||||
provides: "actionService",
|
provides: "actionService",
|
||||||
implementation: ActionDialogDecorator,
|
implementation: ActionDialogDecorator,
|
||||||
depends: [ "mct", "newViews[]" ]
|
depends: [ "openmct", "newViews[]" ]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
policies: [
|
policies: [
|
||||||
{
|
{
|
||||||
category: "composition",
|
category: "composition",
|
||||||
implementation: AdapterCompositionPolicy,
|
implementation: AdapterCompositionPolicy,
|
||||||
depends: [ "mct" ]
|
depends: [ "openmct" ]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
licenses: [
|
licenses: [
|
||||||
|
@ -22,11 +22,9 @@
|
|||||||
|
|
||||||
define([
|
define([
|
||||||
'./object-utils',
|
'./object-utils',
|
||||||
'./ObjectAPI',
|
|
||||||
'./objectEventEmitter'
|
'./objectEventEmitter'
|
||||||
], function (
|
], function (
|
||||||
utils,
|
utils,
|
||||||
ObjectAPI,
|
|
||||||
objectEventEmitter
|
objectEventEmitter
|
||||||
) {
|
) {
|
||||||
function ObjectServiceProvider(objectService, instantiate, topic) {
|
function ObjectServiceProvider(objectService, instantiate, topic) {
|
||||||
@ -98,12 +96,12 @@ define([
|
|||||||
|
|
||||||
// Injects new object API as a decorator so that it hijacks all requests.
|
// Injects new object API as a decorator so that it hijacks all requests.
|
||||||
// Object providers implemented on new API should just work, old API should just work, many things may break.
|
// Object providers implemented on new API should just work, old API should just work, many things may break.
|
||||||
function LegacyObjectAPIInterceptor(ROOTS, instantiate, topic, objectService) {
|
function LegacyObjectAPIInterceptor(openmct, ROOTS, instantiate, topic, objectService) {
|
||||||
this.getObjects = function (keys) {
|
this.getObjects = function (keys) {
|
||||||
var results = {},
|
var results = {},
|
||||||
promises = keys.map(function (keyString) {
|
promises = keys.map(function (keyString) {
|
||||||
var key = utils.parseKeyString(keyString);
|
var key = utils.parseKeyString(keyString);
|
||||||
return ObjectAPI.get(key)
|
return openmct.objects.get(key)
|
||||||
.then(function (object) {
|
.then(function (object) {
|
||||||
object = utils.toOldFormat(object)
|
object = utils.toOldFormat(object)
|
||||||
results[keyString] = instantiate(object, keyString);
|
results[keyString] = instantiate(object, keyString);
|
||||||
@ -116,12 +114,12 @@ define([
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
ObjectAPI._supersecretSetFallbackProvider(
|
openmct.objects._supersecretSetFallbackProvider(
|
||||||
new ObjectServiceProvider(objectService, instantiate, topic)
|
new ObjectServiceProvider(objectService, instantiate, topic)
|
||||||
);
|
);
|
||||||
|
|
||||||
ROOTS.forEach(function (r) {
|
ROOTS.forEach(function (r) {
|
||||||
ObjectAPI.addRoot(utils.parseKeyString(r.id));
|
openmct.objects.addRoot(utils.parseKeyString(r.id));
|
||||||
});
|
});
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -37,33 +37,33 @@ define([
|
|||||||
* @memberof module:openmct
|
* @memberof module:openmct
|
||||||
* @implements {module:openmct.ObjectProvider}
|
* @implements {module:openmct.ObjectProvider}
|
||||||
*/
|
*/
|
||||||
var Objects = {},
|
|
||||||
ROOT_REGISTRY = [],
|
|
||||||
PROVIDER_REGISTRY = {},
|
|
||||||
FALLBACK_PROVIDER;
|
|
||||||
|
|
||||||
Objects._supersecretSetFallbackProvider = function (p) {
|
function ObjectAPI() {
|
||||||
FALLBACK_PROVIDER = p;
|
this.providers = {};
|
||||||
};
|
this.rootRegistry = [];
|
||||||
|
this.rootProvider = {
|
||||||
|
'get': function () {
|
||||||
|
return Promise.resolve({
|
||||||
|
name: 'The root object',
|
||||||
|
type: 'root',
|
||||||
|
composition: this.rootRegistry
|
||||||
|
});
|
||||||
|
}.bind(this)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Root provider is hardcoded in; can't be skipped.
|
ObjectAPI.prototype._supersecretSetFallbackProvider = function (p) {
|
||||||
var RootProvider = {
|
this.fallbackProvider = p;
|
||||||
'get': function () {
|
|
||||||
return Promise.resolve({
|
|
||||||
name: 'The root object',
|
|
||||||
type: 'root',
|
|
||||||
composition: ROOT_REGISTRY
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Retrieve the provider for a given key.
|
// Retrieve the provider for a given key.
|
||||||
function getProvider(key) {
|
ObjectAPI.prototype.getProvider = function (key) {
|
||||||
if (key.identifier === 'ROOT') {
|
if (key.identifier === 'ROOT') {
|
||||||
return RootProvider;
|
return this.rootProvider;
|
||||||
}
|
}
|
||||||
return PROVIDER_REGISTRY[key.namespace] || FALLBACK_PROVIDER;
|
return this.providers[key.namespace] || this.fallbackProvider;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a new object provider for a particular namespace.
|
* Register a new object provider for a particular namespace.
|
||||||
@ -74,8 +74,8 @@ define([
|
|||||||
* @memberof {module:openmct.ObjectAPI#}
|
* @memberof {module:openmct.ObjectAPI#}
|
||||||
* @name addProvider
|
* @name addProvider
|
||||||
*/
|
*/
|
||||||
Objects.addProvider = function (namespace, provider) {
|
ObjectAPI.prototype.addProvider = function (namespace, provider) {
|
||||||
PROVIDER_REGISTRY[namespace] = provider;
|
this.providers[namespace] = provider;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -125,9 +125,9 @@ define([
|
|||||||
'delete',
|
'delete',
|
||||||
'get'
|
'get'
|
||||||
].forEach(function (method) {
|
].forEach(function (method) {
|
||||||
Objects[method] = function () {
|
ObjectAPI.prototype[method] = function () {
|
||||||
var key = arguments[0],
|
var key = arguments[0],
|
||||||
provider = getProvider(key);
|
provider = this.getProvider(key);
|
||||||
|
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
throw new Error('No Provider Matched');
|
throw new Error('No Provider Matched');
|
||||||
@ -148,8 +148,8 @@ define([
|
|||||||
* @method addRoot
|
* @method addRoot
|
||||||
* @memberof module:openmct.ObjectAPI#
|
* @memberof module:openmct.ObjectAPI#
|
||||||
*/
|
*/
|
||||||
Objects.addRoot = function (key) {
|
ObjectAPI.prototype.addRoot = function (key) {
|
||||||
ROOT_REGISTRY.unshift(key);
|
this.rootRegistry.unshift(key);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -159,8 +159,8 @@ define([
|
|||||||
* @method removeRoot
|
* @method removeRoot
|
||||||
* @memberof module:openmct.ObjectAPI#
|
* @memberof module:openmct.ObjectAPI#
|
||||||
*/
|
*/
|
||||||
Objects.removeRoot = function (key) {
|
ObjectAPI.prototype.removeRoot = function (key) {
|
||||||
ROOT_REGISTRY = ROOT_REGISTRY.filter(function (k) {
|
this.rootRegistry = this.rootRegistry.filter(function (k) {
|
||||||
return (
|
return (
|
||||||
k.identifier !== key.identifier ||
|
k.identifier !== key.identifier ||
|
||||||
k.namespace !== key.namespace
|
k.namespace !== key.namespace
|
||||||
@ -176,7 +176,7 @@ define([
|
|||||||
* @method mutate
|
* @method mutate
|
||||||
* @memberof module:openmct.ObjectAPI#
|
* @memberof module:openmct.ObjectAPI#
|
||||||
*/
|
*/
|
||||||
Objects.mutate = function (domainObject, path, value) {
|
ObjectAPI.prototype.mutate = function (domainObject, path, value) {
|
||||||
return new MutableObject(domainObject).set(path, value);
|
return new MutableObject(domainObject).set(path, value);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ define([
|
|||||||
* @method observe
|
* @method observe
|
||||||
* @memberof module:openmct.ObjectAPI#
|
* @memberof module:openmct.ObjectAPI#
|
||||||
*/
|
*/
|
||||||
Objects.observe = function (domainObject, path, callback) {
|
ObjectAPI.prototype.observe = function (domainObject, path, callback) {
|
||||||
return new MutableObject(domainObject).on(path, callback);
|
return new MutableObject(domainObject).on(path, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -228,5 +228,5 @@ define([
|
|||||||
* @memberof module:openmct
|
* @memberof module:openmct
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return Objects;
|
return ObjectAPI;
|
||||||
});
|
});
|
||||||
|
@ -39,6 +39,7 @@ define([
|
|||||||
priority: "mandatory",
|
priority: "mandatory",
|
||||||
implementation: LegacyObjectAPIInterceptor,
|
implementation: LegacyObjectAPIInterceptor,
|
||||||
depends: [
|
depends: [
|
||||||
|
"openmct",
|
||||||
"roots[]",
|
"roots[]",
|
||||||
"instantiate",
|
"instantiate",
|
||||||
"topic"
|
"topic"
|
||||||
|
Reference in New Issue
Block a user