From 0e7d812db724e6bbac50f84363f87091f3a738b7 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 7 Sep 2016 13:04:30 -0700 Subject: [PATCH] [API] Document ObjectAPI registration --- API.md | 31 ++++++++++++++++++++++++++++++- src/api/objects/ObjectAPI.js | 4 ++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/API.md b/API.md index 822e3619d1..e1fbef72a2 100644 --- a/API.md +++ b/API.md @@ -106,13 +106,40 @@ openmct.mainViews.addProvider({ }); ``` +### Adding a Root-level Object + +In many cases, you'd like a certain object (or a certain hierarchy of +objects) to be accessible from the top level of the application (the +tree on the left-hand side of Open MCT.) It is typical to expose a telemetry +dictionary as a hierarchy of telemetry-providing domain objects in this +fashion. + +To do so, use the [`addRoot`]{@link module:openmct.ObjectAPI#addRoot} method +of the [object API]{@link module:openmct.ObjectAPI}: + +``` +openmct.objects.addRoot({ + identifier: { key: "my-key", namespace: "my-namespace" } + name: "My Root-level Object", + type: "my-type" +}); +``` + +You can also remove this root-level object via its identifier: + +``` +openmct.objects.removeRoot({ key: "my-key", namespace: "my-namespace" }); +``` + ### Adding Composition Providers The "composition" of a domain object is the list of objects it contains, as shown (for example) in the tree for browsing. Open MCT provides a default solution for composition, but there may be cases where you want to provide the composition of a certain object (or type of object) dynamically. -For this, you can add a new CompositionProvider: +For instance, you may want to populate a hierarchy under a custom root-level +object based on the contents of a telemetry dictionary. +To do this, you can add a new CompositionProvider: ``` openmct.composition.addProvider({ @@ -126,6 +153,8 @@ openmct.composition.addProvider({ ``` + + ## Using Open MCT When implementing new features, it is useful and sometimes necessary to diff --git a/src/api/objects/ObjectAPI.js b/src/api/objects/ObjectAPI.js index afd804d318..9e8deabb46 100644 --- a/src/api/objects/ObjectAPI.js +++ b/src/api/objects/ObjectAPI.js @@ -125,8 +125,8 @@ define([ /** * Add a root-level object. - * @param {module:openmct.ObjectAPI~Identifier} id the identifier of the - * root-level object to add. + * @param {module:openmct.DomainObject} domainObject the root-level object + * to add. * @method addRoot * @memberof module:openmct.ObjectAPI# */