diff options
Diffstat (limited to 'js/service/Publisher.js')
-rw-r--r-- | js/service/Publisher.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/js/service/Publisher.js b/js/service/Publisher.js new file mode 100644 index 000000000..da9b0a470 --- /dev/null +++ b/js/service/Publisher.js @@ -0,0 +1,38 @@ +/** + * 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.publishAll = function (data) { + var channel, + counter; + + for (channel in data) { + if (data.hasOwnProperty(channel) && this.channels[channel] !== undefined) { + for (counter = 0; counter < this.channels[channel].length; counter += 1) { + this.channels[channel][counter].receive(data[channel]); + } + } + } + }; + +});
\ No newline at end of file |