[API] More Objects doc

This commit is contained in:
Victor Woeltjen 2016-09-06 08:31:42 -07:00
parent 1abcb248fe
commit a20e8d69b5

View File

@ -19,6 +19,7 @@ define([
* Utilities for loading, saving, and manipulating domain objects.
* @interface ObjectAPI
* @memberof module:openmct
* @implements {module:openmct.ObjectProvider}
*/
var Objects = {},
ROOT_REGISTRY = [],
@ -49,10 +50,61 @@ define([
return PROVIDER_REGISTRY[key.namespace] || FALLBACK_PROVIDER;
}
/**
* Register a new object provider for a particular namespace.
*
* @param {string} namespace the namespace for which to provide objects
* @param {module:openmct.ObjectProvider} provider the provider which
* will handle loading domain objects from this namespace
* @memberof {module:openmct.ObjectAPI#}
* @name addProvider
*/
Objects.addProvider = function (namespace, provider) {
PROVIDER_REGISTRY[namespace] = provider;
};
/**
* Provides the ability to read, write, and delete domain objects.
*
* When registering a new object provider, all methods on this interface
* are optional.
*
* @interface ObjectProvider
* @memberof module:openmct
*/
/**
* Save this domain object in its current state.
*
* @method save
* @memberof module:openmct.ObjectProvider#
* @param {module:openmct.DomainObject} domainObject the domain object to
* save
* @returns {Promise} a promise which will resolve when the domain object
* has been saved, or be rejected if it cannot be saved
*/
/**
* Delete this domain object.
*
* @method delete
* @memberof module:openmct.ObjectProvider#
* @param {module:openmct.DomainObject} domainObject the domain object to
* delete
* @returns {Promise} a promise which will resolve when the domain object
* has been deleted, or be rejected if it cannot be deleted
*/
/**
* Get a domain object.
*
* @method get
* @memberof module:openmct.ObjectProvider#
* @param {string} key the key for the domain object to load
* @returns {Promise} a promise which will resolve when the domain object
* has been saved, or be rejected if it cannot be saved
*/
[
'save',
'delete',
@ -74,10 +126,24 @@ define([
};
});
/**
* Add a root-level object.
* @param {module:openmct.Identifier} the identifier of the root-level
* object to add.
* @method addRoot
* @memberof module:openmct.ObjectAPI#
*/
Objects.addRoot = function (key) {
ROOT_REGISTRY.unshift(key);
};
/**
* Remove a root-level object.
* @param {module:openmct.Identifier} the identifier of the root-level
* object to remove.
* @method removeRoot
* @memberof module:openmct.ObjectAPI#
*/
Objects.removeRoot = function (key) {
ROOT_REGISTRY = ROOT_REGISTRY.filter(function (k) {
return (
@ -91,5 +157,16 @@ define([
return new MutableObject(eventEmitter, object);
};
/**
* Uniquely identifies a domain object.
*
* @typedef Identifier
* @memberof module:openmct
* @property {string} namespace the namespace to/from which this domain
* object should be loaded/stored.
* @property {string} key a unique identifier for the domain object
* within that namespace
*/
return Objects;
});