mirror of
https://github.com/nasa/openmct.git
synced 2024-12-19 13:17:53 +00:00
[API] get with keystring, mark methods not implemented
Update Object API such that get supports calls with either a keystring or an identifier. As save and delete are not implemented and have different calling signatures, implement them as separate methods so they can be documented separately.
This commit is contained in:
parent
bda30f1475
commit
c533e10352
@ -50,11 +50,18 @@ define([
|
|||||||
this.rootProvider = new RootObjectProvider(this.rootRegistry);
|
this.rootProvider = new RootObjectProvider(this.rootRegistry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set fallback provider, this is an internal API for legacy reasons.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
ObjectAPI.prototype.supersecretSetFallbackProvider = function (p) {
|
ObjectAPI.prototype.supersecretSetFallbackProvider = function (p) {
|
||||||
this.fallbackProvider = p;
|
this.fallbackProvider = p;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Retrieve the provider for a given key.
|
/**
|
||||||
|
* Retrieve the provider for a given identifier.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
ObjectAPI.prototype.getProvider = function (identifier) {
|
ObjectAPI.prototype.getProvider = function (identifier) {
|
||||||
if (identifier.key === 'ROOT') {
|
if (identifier.key === 'ROOT') {
|
||||||
return this.rootProvider;
|
return this.rootProvider;
|
||||||
@ -135,27 +142,28 @@ define([
|
|||||||
* @returns {Promise} a promise which will resolve when the domain object
|
* @returns {Promise} a promise which will resolve when the domain object
|
||||||
* has been saved, or be rejected if it cannot be saved
|
* has been saved, or be rejected if it cannot be saved
|
||||||
*/
|
*/
|
||||||
|
ObjectAPI.prototype.get = function (identifier) {
|
||||||
[
|
identifier = utils.parseKeyString(identifier);
|
||||||
'save',
|
var provider = this.getProvider(identifier);
|
||||||
'delete',
|
|
||||||
'get'
|
|
||||||
].forEach(function (method) {
|
|
||||||
ObjectAPI.prototype[method] = function () {
|
|
||||||
var identifier = arguments[0],
|
|
||||||
provider = this.getProvider(identifier);
|
|
||||||
|
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
throw new Error('No Provider Matched');
|
throw new Error('No Provider Matched');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!provider[method]) {
|
if (!provider.get) {
|
||||||
throw new Error('Provider does not support [' + method + '].');
|
throw new Error('Provider does not support get!');
|
||||||
}
|
}
|
||||||
|
|
||||||
return provider[method].apply(provider, arguments);
|
return provider.get(identifier);
|
||||||
|
};
|
||||||
|
|
||||||
|
ObjectAPI.prototype.delete = function () {
|
||||||
|
throw new Error('Delete not implemented');
|
||||||
|
};
|
||||||
|
|
||||||
|
ObjectAPI.prototype.save = function () {
|
||||||
|
throw new Error('Save not implemented');
|
||||||
};
|
};
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a root-level object.
|
* Add a root-level object.
|
||||||
|
Loading…
Reference in New Issue
Block a user