From 074958317f06726ee9f97ea42dab88e852aa0d8e Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 5 Nov 2014 17:38:14 -0800 Subject: [PATCH] [Example] Add composite services example Add an example showing the use of composite services, WTD-518. --- example/composite/bundle.json | 37 +++++++++++++++++++++ example/composite/src/SomeAggregator.js | 29 ++++++++++++++++ example/composite/src/SomeDecorator.js | 27 +++++++++++++++ example/composite/src/SomeOtherDecorator.js | 27 +++++++++++++++ example/composite/src/SomeOtherExample.js | 25 ++++++++++++++ example/composite/src/SomeOtherProvider.js | 27 +++++++++++++++ example/composite/src/SomeProvider.js | 27 +++++++++++++++ 7 files changed, 199 insertions(+) create mode 100644 example/composite/bundle.json create mode 100644 example/composite/src/SomeAggregator.js create mode 100644 example/composite/src/SomeDecorator.js create mode 100644 example/composite/src/SomeOtherDecorator.js create mode 100644 example/composite/src/SomeOtherExample.js create mode 100644 example/composite/src/SomeOtherProvider.js create mode 100644 example/composite/src/SomeProvider.js diff --git a/example/composite/bundle.json b/example/composite/bundle.json new file mode 100644 index 0000000000..4ec72d0854 --- /dev/null +++ b/example/composite/bundle.json @@ -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" ] + } + ] + } +} \ No newline at end of file diff --git a/example/composite/src/SomeAggregator.js b/example/composite/src/SomeAggregator.js new file mode 100644 index 0000000000..b54dc36429 --- /dev/null +++ b/example/composite/src/SomeAggregator.js @@ -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; + } +); \ No newline at end of file diff --git a/example/composite/src/SomeDecorator.js b/example/composite/src/SomeDecorator.js new file mode 100644 index 0000000000..3b14b6674c --- /dev/null +++ b/example/composite/src/SomeDecorator.js @@ -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; + } +); \ No newline at end of file diff --git a/example/composite/src/SomeOtherDecorator.js b/example/composite/src/SomeOtherDecorator.js new file mode 100644 index 0000000000..6f0922c616 --- /dev/null +++ b/example/composite/src/SomeOtherDecorator.js @@ -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; + } +); \ No newline at end of file diff --git a/example/composite/src/SomeOtherExample.js b/example/composite/src/SomeOtherExample.js new file mode 100644 index 0000000000..696958aaf3 --- /dev/null +++ b/example/composite/src/SomeOtherExample.js @@ -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; + } +); \ No newline at end of file diff --git a/example/composite/src/SomeOtherProvider.js b/example/composite/src/SomeOtherProvider.js new file mode 100644 index 0000000000..ecdea59e75 --- /dev/null +++ b/example/composite/src/SomeOtherProvider.js @@ -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; + } +); \ No newline at end of file diff --git a/example/composite/src/SomeProvider.js b/example/composite/src/SomeProvider.js new file mode 100644 index 0000000000..cca7f0e8be --- /dev/null +++ b/example/composite/src/SomeProvider.js @@ -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; + } +); \ No newline at end of file