diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-19 15:51:26 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-19 15:51:26 +0200 |
commit | 11f0246acd0daab1067eb32099fa26f05a26ea21 (patch) | |
tree | 67012a66a89be2f43910dee41a6e023d7645b29b /js/service | |
parent | 928ccf49fb5c6deb405358ad38221b0cd205fb6b (diff) |
subscribe to more channels and fetch more feeds on init
Diffstat (limited to 'js/service')
-rw-r--r-- | js/service/Item.js | 24 | ||||
-rw-r--r-- | js/service/Publisher.js | 13 |
2 files changed, 33 insertions, 4 deletions
diff --git a/js/service/Item.js b/js/service/Item.js index 0dd9b8677..ec3512f22 100644 --- a/js/service/Item.js +++ b/js/service/Item.js @@ -16,5 +16,29 @@ app.factory('Item', function (Model) { Item.prototype = Object.create(Model.prototype); + Item.prototype.receive = function (value, channel) { + switch (channel) { + + case 'newestItemId': + this.newestItemId = value; + break; + + case 'starred': + this.starredCount = value; + break; + default: + Model.prototype.receive.call(this, value, channel); + } + }; + + Item.prototype.getNewestItemId = function () { + return this.newestItemId; + }; + + Item.prototype.getStarredCount = function () { + return this.starredCount; + }; + + return new Item(); });
\ No newline at end of file diff --git a/js/service/Publisher.js b/js/service/Publisher.js index da9b0a470..784b2fff6 100644 --- a/js/service/Publisher.js +++ b/js/service/Publisher.js @@ -15,9 +15,14 @@ app.service('Publisher', function () { this.subscribe = function (object) { return { - toChannel: function (channel) { - self.channels[channel] = self.channels[channel] || []; - self.channels[channel].push(object); + toChannels: function () { + var counter, + channel; + for (counter = 0; counter < arguments.length; counter += 1) { + channel = arguments[counter]; + self.channels[channel] = self.channels[channel] || []; + self.channels[channel].push(object); + } } }; }; @@ -29,7 +34,7 @@ app.service('Publisher', function () { 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]); + this.channels[channel][counter].receive(data[channel], channel); } } } |