[API] Exemplify mutate/observe

This commit is contained in:
Victor Woeltjen 2016-09-07 13:10:48 -07:00
parent 0e7d812db7
commit 616e2b4d77

25
API.md
View File

@ -152,9 +152,6 @@ openmct.composition.addProvider({
}); });
``` ```
## Using Open MCT ## Using Open MCT
When implementing new features, it is useful and sometimes necessary to When implementing new features, it is useful and sometimes necessary to
@ -193,6 +190,28 @@ a view (or part of a view) selectable:
openmct.gestures.selectable(myHtmlElement, myDomainObject); openmct.gestures.selectable(myHtmlElement, myDomainObject);
``` ```
### Working with Domain Objects
The [object API]{@link module:openmct.ObjectAPI} provides useful methods
for working with domain objects.
To make changes to a domain object, use the
[`mutate`]{@link module:openmct.ObjectAPI#mutate} method:
```
openmct.objects.mutate(myDomainObject, "name", "New name!");
```
Making modifications in this fashion allows other usages of the domain
object to remain up to date using the
[`observe`]{@link module:openmct.ObjectAPI#observe} method:
```
openmct.objects.observe(myDomainObject, "name", function (newName) {
myLabel.textContent = newName;
});
```
## Plugins ## Plugins
While you can register new features with Open MCT directly, it is generally While you can register new features with Open MCT directly, it is generally