mirror of
https://github.com/nasa/openmct.git
synced 2024-12-30 09:58:52 +00:00
d5aa998b4c
* [Objects] util for equality checking Add a method for checking object equality, useful for other services. * [Composition] Draft Composition API Draft composition API. Composition collections provide an observable for watching and mutating the composition of an object. Composition providers implement the loading and modification of composition. The default composition provider uses the composition attribute of domain objects, while allowing other providers to implement their own loading and mutation behavior. * add todo about event listener bindings * [Type] Add form property for defining form fields * [tutorial] Add Composition tutorial * provider doesn't have to implement events, load returns array of children * use new composition in old api * correct key name * Override instantiate to provide model ids Override instantiate in public API adapter to prevent making changes to platform code. Instantiate now passes the id of the domain object with the model so that capabilities can convert to a new-style domain object and use that to detect functionality. * Implement mutation capability with decorator Implementation mutation capability override with decorator to adapter code outside of platform. Capability override ensures that models are kept in sync even though they are no longer shared objects. * override composition cleanly Override composition capability without making changes inside platform. * cleanup after temporary collections * remove unused try/catch
66 lines
1.8 KiB
HTML
66 lines
1.8 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
|
<title>Implementing a composition provider</title>
|
|
<script src="dist/main.js"></script>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
|
|
var widgetParts = ['foo', 'bar', 'baz', 'bing', 'frobnak']
|
|
|
|
function fabricateName() {
|
|
return [
|
|
widgetParts[Math.floor(Math.random() * widgetParts.length)],
|
|
widgetParts[Math.floor(Math.random() * widgetParts.length)],
|
|
Math.floor(Math.random() * 1000)
|
|
].join('_');
|
|
}
|
|
|
|
MCT.type('example.widget-factory', new MCT.Type({
|
|
metadata: {
|
|
label: "Widget Factory",
|
|
glyph: "s",
|
|
description: "A factory for making widgets"
|
|
},
|
|
initialize: function (object) {
|
|
object.widgetCount = 5;
|
|
object.composition = [];
|
|
},
|
|
creatable: true,
|
|
form: [
|
|
{
|
|
name: "Widget Count",
|
|
control: "textfield",
|
|
key: "widgetCount",
|
|
property: "widgetCount",
|
|
required: true
|
|
}
|
|
]
|
|
}));
|
|
|
|
MCT.Composition.addProvider({
|
|
appliesTo: function (domainObject) {
|
|
return domainObject.type === 'example.widget-factory';
|
|
},
|
|
load: function (domainObject) {
|
|
var widgets = [];
|
|
while (widgets.length < domainObject.widgetCount) {
|
|
widgets.push({
|
|
name: fabricateName(),
|
|
key: {
|
|
namespace: 'widget-factory',
|
|
identifier: '' + widgets.length
|
|
}
|
|
});
|
|
}
|
|
return Promise.resolve(widgets);
|
|
}
|
|
});
|
|
|
|
MCT.run();
|
|
</script>
|
|
</body>
|
|
</html>
|