summaryrefslogtreecommitdiffstats
path: root/js-old/service/Publisher.js
diff options
context:
space:
mode:
Diffstat (limited to 'js-old/service/Publisher.js')
-rw-r--r--js-old/service/Publisher.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/js-old/service/Publisher.js b/js-old/service/Publisher.js
new file mode 100644
index 000000000..0d0dcf9eb
--- /dev/null
+++ b/js-old/service/Publisher.js
@@ -0,0 +1,44 @@
+/**
+ * Nextcloud - 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
+ */
+
+/*jshint undef:false*/
+app.service('Publisher', function () {
+ 'use strict';
+
+ this.channels = {};
+
+ this.subscribe = function (obj) {
+ var self = this;
+
+ return {
+ toChannels: function (channels) {
+ channels.forEach(function (channel) {
+ self.channels[channel] = self.channels[channel] || [];
+ self.channels[channel].push(obj);
+ });
+ }
+ };
+
+ };
+
+ this.publishAll = function (data) {
+ var self = this;
+
+ Object.keys(data).forEach(function (channel) {
+ var listeners = self.channels[channel];
+ if (listeners !== undefined) {
+ listeners.forEach(function (listener) {
+ listener.receive(data[channel], channel);
+ });
+ }
+ });
+ };
+
+}); \ No newline at end of file