[Example] Add composite services example

Add an example showing the use of composite services,
WTD-518.
This commit is contained in:
Victor Woeltjen 2014-11-05 17:38:14 -08:00
parent 3cbdb0b9e2
commit 074958317f
7 changed files with 199 additions and 0 deletions

View 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" ]
}
]
}
}

View 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;
}
);

View 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;
}
);

View 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;
}
);

View 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;
}
);

View 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;
}
);

View 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;
}
);