mirror of
https://github.com/nasa/openmct.git
synced 2025-01-19 11:17:04 +00:00
[Example] Add composite services example
Add an example showing the use of composite services, WTD-518.
This commit is contained in:
parent
3cbdb0b9e2
commit
074958317f
37
example/composite/bundle.json
Normal file
37
example/composite/bundle.json
Normal file
@ -0,0 +1,37 @@
|
||||
{
|
||||
"extensions": {
|
||||
"components": [
|
||||
{
|
||||
"implementation": "SomeProvider.js",
|
||||
"provides": "someService",
|
||||
"type": "provider"
|
||||
},
|
||||
{
|
||||
"implementation": "SomeOtherProvider.js",
|
||||
"provides": "someService",
|
||||
"type": "provider"
|
||||
},
|
||||
{
|
||||
"implementation": "SomeDecorator.js",
|
||||
"provides": "someService",
|
||||
"type": "decorator"
|
||||
},
|
||||
{
|
||||
"implementation": "SomeOtherDecorator.js",
|
||||
"provides": "someService",
|
||||
"type": "decorator"
|
||||
},
|
||||
{
|
||||
"implementation": "SomeAggregator.js",
|
||||
"provides": "someService",
|
||||
"type": "aggregator"
|
||||
}
|
||||
],
|
||||
"examples": [
|
||||
{
|
||||
"implementation": "SomeOtherExample.js",
|
||||
"depends": [ "someService" ]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
29
example/composite/src/SomeAggregator.js
Normal file
29
example/composite/src/SomeAggregator.js
Normal file
@ -0,0 +1,29 @@
|
||||
/*global define,Promise*/
|
||||
|
||||
/**
|
||||
* Module defining SomeAggregator. Created by vwoeltje on 11/5/14.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function SomeAggregator(someProviders) {
|
||||
return {
|
||||
getMessages: function () {
|
||||
return someProviders.map(function (provider) {
|
||||
return provider.getMessages();
|
||||
}).reduce(function (a, b) {
|
||||
return a.concat(b);
|
||||
}, []);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return SomeAggregator;
|
||||
}
|
||||
);
|
27
example/composite/src/SomeDecorator.js
Normal file
27
example/composite/src/SomeDecorator.js
Normal file
@ -0,0 +1,27 @@
|
||||
/*global define,Promise*/
|
||||
|
||||
/**
|
||||
* Module defining SomeDecorator. Created by vwoeltje on 11/5/14.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function SomeDecorator(someProvider) {
|
||||
return {
|
||||
getMessages: function () {
|
||||
return someProvider.getMessages().map(function (msg) {
|
||||
return msg.toLocaleUpperCase();
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return SomeDecorator;
|
||||
}
|
||||
);
|
27
example/composite/src/SomeOtherDecorator.js
Normal file
27
example/composite/src/SomeOtherDecorator.js
Normal file
@ -0,0 +1,27 @@
|
||||
/*global define,Promise*/
|
||||
|
||||
/**
|
||||
* Module defining SomeOtherDecorator. Created by vwoeltje on 11/5/14.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function SomeOtherDecorator(someProvider) {
|
||||
return {
|
||||
getMessages: function () {
|
||||
return someProvider.getMessages().map(function (msg) {
|
||||
return msg + "...";
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return SomeOtherDecorator;
|
||||
}
|
||||
);
|
25
example/composite/src/SomeOtherExample.js
Normal file
25
example/composite/src/SomeOtherExample.js
Normal file
@ -0,0 +1,25 @@
|
||||
/*global define,Promise*/
|
||||
|
||||
/**
|
||||
* Module defining SomeOtherExample. Created by vwoeltje on 11/5/14.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function SomeOtherExample(someService) {
|
||||
return {
|
||||
getText: function () {
|
||||
return someService.getMessages().join(" | ");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return SomeOtherExample;
|
||||
}
|
||||
);
|
27
example/composite/src/SomeOtherProvider.js
Normal file
27
example/composite/src/SomeOtherProvider.js
Normal file
@ -0,0 +1,27 @@
|
||||
/*global define,Promise*/
|
||||
|
||||
/**
|
||||
* Module defining SomeOtherProvider. Created by vwoeltje on 11/5/14.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function SomeOtherProvider() {
|
||||
return {
|
||||
getMessages: function () {
|
||||
return [
|
||||
"I am a message from some other provider."
|
||||
];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return SomeOtherProvider;
|
||||
}
|
||||
);
|
27
example/composite/src/SomeProvider.js
Normal file
27
example/composite/src/SomeProvider.js
Normal file
@ -0,0 +1,27 @@
|
||||
/*global define,Promise*/
|
||||
|
||||
/**
|
||||
* Module defining SomeProvider. Created by vwoeltje on 11/5/14.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function SomeProvider() {
|
||||
return {
|
||||
getMessages: function () {
|
||||
return [
|
||||
"I am a message from some provider."
|
||||
];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return SomeProvider;
|
||||
}
|
||||
);
|
Loading…
Reference in New Issue
Block a user