diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-18 22:56:44 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-18 22:56:44 +0200 |
commit | ded252d29e99e068ea341506129e47a05e053a24 (patch) | |
tree | d91167136238df80d6d638c1243bb1aa29058460 /js | |
parent | 2459002dcc070dcb66b2a44c237b87e8a1b8e968 (diff) |
register publisher
Diffstat (limited to 'js')
-rw-r--r-- | js/app/run.js | 10 | ||||
-rw-r--r-- | js/build/app.js | 34 | ||||
-rw-r--r-- | js/service/publisher.js | 24 | ||||
-rw-r--r-- | js/tests/unit/service/PublisherSpec.js | 11 |
4 files changed, 37 insertions, 42 deletions
diff --git a/js/app/run.js b/js/app/run.js index 00e71a7b0..f91d908f2 100644 --- a/js/app/run.js +++ b/js/app/run.js @@ -7,9 +7,17 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -app.run(function ($rootScope, $location, Loading, Setup) { +app.run(function ($rootScope, $location, Loading, Setup, Item, Feed, Folder, + Publisher, Settings) { 'use strict'; + // listen to keys in returned queries to automatically distribute the + // incoming values to models + Publisher.subscribe(Item).toChannel('items'); + Publisher.subscribe(Folder).toChannel('folders'); + Publisher.subscribe(Feed).toChannel('feeds'); + Publisher.subscribe(Settings).toChannel('settings'); + // load feeds, settings and last read feed Setup.load(); diff --git a/js/build/app.js b/js/build/app.js index 8c5835c06..3a72dc277 100644 --- a/js/build/app.js +++ b/js/build/app.js @@ -38,8 +38,19 @@ app.run([ '$location', 'Loading', 'Setup', - function ($rootScope, $location, Loading, Setup) { + 'Item', + 'Feed', + 'Folder', + 'Publisher', + 'Settings', + function ($rootScope, $location, Loading, Setup, Item, Feed, Folder, Publisher, Settings) { 'use strict'; + // listen to keys in returned queries to automatically distribute the + // incoming values to models + Publisher.subscribe(Item).toChannel('items'); + Publisher.subscribe(Folder).toChannel('folders'); + Publisher.subscribe(Feed).toChannel('feeds'); + Publisher.subscribe(Settings).toChannel('settings'); // load feeds, settings and last read feed Setup.load(); $rootScope.$on('$routeChangeStart', function () { @@ -175,23 +186,16 @@ app.service('Publisher', function () { } }; }; - this.publishAll = function (values) { - var key; - for (key in values) { - if (values.hasOwnProperty(key)) { - this.publish(values[key]).onChannel(key); + this.publishAll = function (data) { + var channel, counter; + for (channel in data) { + if (data.hasOwnProperty(channel)) { + for (counter = 0; counter < this.channels[channel].length; counter += 1) { + this.channels[channel][counter].receive(data[channel]); + } } } }; - this.publish = function (value) { - return { - onChannel: function (channel) { - self.channels[channel].forEach(function (object) { - object.receive(value); - }); - } - }; - }; }); app.service('Setup', function () { 'use strict'; diff --git a/js/service/publisher.js b/js/service/publisher.js index d7e9bb0e7..db8a1d5db 100644 --- a/js/service/publisher.js +++ b/js/service/publisher.js @@ -22,23 +22,17 @@ app.service('Publisher', function () { }; }; - this.publishAll = function (values) { - var key; - for (key in values) { - if (values.hasOwnProperty(key)) { - this.publish(values[key]).onChannel(key); - } - } - }; + this.publishAll = function (data) { + var channel, + counter; - this.publish = function (value) { - return { - onChannel: function (channel) { - self.channels[channel].forEach(function (object) { - object.receive(value); - }); + for (channel in data) { + if (data.hasOwnProperty(channel)) { + for (counter = 0; counter < this.channels[channel].length; counter += 1) { + this.channels[channel][counter].receive(data[channel]); + } } - }; + } }; });
\ No newline at end of file diff --git a/js/tests/unit/service/PublisherSpec.js b/js/tests/unit/service/PublisherSpec.js index 59628356f..f7fa67796 100644 --- a/js/tests/unit/service/PublisherSpec.js +++ b/js/tests/unit/service/PublisherSpec.js @@ -12,17 +12,6 @@ describe('Publisher', function () { beforeEach(module('News')); - it('should subscribe an object and publish a message', inject(function (Publisher) { - var obj = { - receive: jasmine.createSpy('receive') - }; - Publisher.subscribe(obj).toChannel('test'); - - Publisher.publish('tom').onChannel('test'); - expect(obj.receive).toHaveBeenCalledWith('tom'); - })); - - it('should should publish on all possible channels', inject(function (Publisher) { var obj = { |