diff options
Diffstat (limited to 'js/service/publisher.js')
-rw-r--r-- | js/service/publisher.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/js/service/publisher.js b/js/service/publisher.js new file mode 100644 index 000000000..185e60047 --- /dev/null +++ b/js/service/publisher.js @@ -0,0 +1,35 @@ +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.service('Publisher', function () { + 'use strict'; + + var self = this; + this.channels = {}; + + this.subscribe = function (object) { + return { + toChannel: function (channel) { + self.channels[channel] = self.channels[channel] || []; + self.channels[channel].push(object); + } + }; + }; + + this.publish = function (value) { + return { + onChannel: function (channel) { + self.channels[channel].forEach(function (object) { + object.receive(value); + }); + } + }; + }; + +});
\ No newline at end of file |