/** * ownCloud - News * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * * @author Bernhard Posselt * @copyright Bernhard Posselt 2014 */ /*jshint undef:false*/ app.service('Publisher', function () { 'use strict'; this.channels = {}; this.subscribe = (obj) => { return { toChannels: (...channels) => { for (let channel of channels) { this.channels[channel] = this.channels[channel] || []; this.channels[channel].push(obj); } } }; }; this.publishAll = (data) => { for (let [channel, messages] of items(data)) { if (this.channels[channel] !== undefined) { for(let listener of this.channels[channel]) { listener.receive(messages, channel); } } } }; });