diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-21 23:43:28 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-21 23:43:28 +0200 |
commit | 0fa67552247b2d29a6ca438c2605b8db2bbdbab7 (patch) | |
tree | 8109135e2fc141a324e8f21c66243ee4277b3b7c /js/service | |
parent | d3a774b2bd79654360a3ef12618102abf85a2ce3 (diff) |
es6 all the things
Diffstat (limited to 'js/service')
-rw-r--r-- | js/service/FeedResource.js | 12 | ||||
-rw-r--r-- | js/service/FolderResource.js | 12 | ||||
-rw-r--r-- | js/service/ItemResource.js | 45 | ||||
-rw-r--r-- | js/service/Loading.js | 4 | ||||
-rw-r--r-- | js/service/Publisher.js | 28 | ||||
-rw-r--r-- | js/service/Resource.js | 68 | ||||
-rw-r--r-- | js/service/Settings.js | 13 |
7 files changed, 85 insertions, 97 deletions
diff --git a/js/service/FeedResource.js b/js/service/FeedResource.js index 09de0a607..903a58241 100644 --- a/js/service/FeedResource.js +++ b/js/service/FeedResource.js @@ -7,14 +7,14 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -app.factory('FeedResource', function (Resource, $http) { +app.factory('FeedResource', (Resource, $http) => { 'use strict'; - var FeedResource = function ($http) { - Resource.call(this, 'url', $http); - }; - - FeedResource.prototype = Object.create(Resource.prototype); + class FeedResource extends Resource { + constructor ($http) { + super('url', $http); + } + } return new FeedResource($http); });
\ No newline at end of file diff --git a/js/service/FolderResource.js b/js/service/FolderResource.js index 30026b9a2..b1c0271dd 100644 --- a/js/service/FolderResource.js +++ b/js/service/FolderResource.js @@ -7,14 +7,14 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -app.factory('FolderResource', function (Resource, $http) { +app.factory('FolderResource', (Resource, $http) => { 'use strict'; - var FolderResource = function ($http) { - Resource.call(this, 'name', $http); - }; - - FolderResource.prototype = Object.create(Resource.prototype); + class FolderResource extends Resource { + constructor ($http) { + super('name', $http); + } + } return new FolderResource($http); });
\ No newline at end of file diff --git a/js/service/ItemResource.js b/js/service/ItemResource.js index 9b13f07c7..8cb47d527 100644 --- a/js/service/ItemResource.js +++ b/js/service/ItemResource.js @@ -7,38 +7,39 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -app.factory('ItemResource', function (Resource, $http) { +app.factory('ItemResource', (Resource, $http) => { 'use strict'; - var ItemResource = function ($http) { - Resource.call(this, 'id', $http); - }; + class ItemResource extends Resource { - ItemResource.prototype = Object.create(Resource.prototype); + constructor ($http) { + super('id', $http); + } - ItemResource.prototype.receive = function (value, channel) { - switch (channel) { + receive (value, channel) { + switch (channel) { - case 'newestItemId': - this.newestItemId = value; - break; + case 'newestItemId': + this.newestItemId = value; + break; - case 'starred': - this.starredCount = value; - break; - default: - Resource.prototype.receive.call(this, value, channel); + case 'starred': + this.starredCount = value; + break; + default: + super.receive(value, channel); + } } - }; - ItemResource.prototype.getNewestItemId = function () { - return this.newestItemId; - }; + getNewestItemId () { + return this.newestItemId; + } - ItemResource.prototype.getStarredCount = function () { - return this.starredCount; - }; + getStarredCount () { + return this.starredCount; + } + } return new ItemResource($http); });
\ No newline at end of file diff --git a/js/service/Loading.js b/js/service/Loading.js index eb42655a5..c07dba9fe 100644 --- a/js/service/Loading.js +++ b/js/service/Loading.js @@ -16,11 +16,11 @@ app.service('Loading', function () { autopaging: false }; - this.setLoading = function (area, isLoading) { + this.setLoading = (area, isLoading) => { this.loading[area] = isLoading; }; - this.isLoading = function (area) { + this.isLoading = (area) => { return this.loading[area]; }; diff --git a/js/service/Publisher.js b/js/service/Publisher.js index 784b2fff6..b6ea722ce 100644 --- a/js/service/Publisher.js +++ b/js/service/Publisher.js @@ -10,31 +10,25 @@ app.service('Publisher', function () { 'use strict'; - var self = this; this.channels = {}; - this.subscribe = function (object) { + this.subscribe = (obj) => { return { - 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); + toChannels: (...channels) => { + for (let channel of channels) { + this.channels[channel] = this.channels[channel] || []; + this.channels[channel].push(obj); } } }; - }; - 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], channel); + this.publishAll = (data) => { + for (let channel in data) { + if (this.channels[channel] !== undefined) { + for (let listener of this.channels[channel]) { + listener.receive(data[channel], channel); } } } diff --git a/js/service/Resource.js b/js/service/Resource.js index ecae0fcfd..3c17872dc 100644 --- a/js/service/Resource.js +++ b/js/service/Resource.js @@ -7,57 +7,53 @@ * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2014 */ -app.factory('Resource', function () { +app.factory('Resource', () => { 'use strict'; - var Resource = function (id, http) { - this.id = id; - this.values = []; - this.hashMap = {}; - this.http = http; - }; + class Resource { - Resource.prototype = { - receive: function (values) { - var self = this; - values.forEach(function (value) { - self.add(value); - }); - }, + constructor (id, http) { + this.id = id; + this.values = []; + this.hashMap = {}; + this.http = http; + } - add: function (value) { - var key, - existing; + receive (values) { + values.forEach((value) => { + this.add(value); + }); + } - existing = this.hashMap[value[this.id]]; + add (value) { + let existing = this.hashMap[value[this.id]]; if (existing === undefined) { this.values.push(value); this.hashMap[value[this.id]] = value; } else { // copy values from new to old object if it exists already - for (key in value) { + for (let key in value) { if (value.hasOwnProperty(key)) { existing[key] = value[key]; } } } - }, + } - size: function () { + size () { return this.values.length; - }, + } - get: function (id) { + get (id) { return this.hashMap[id]; - }, + } - delete: function (id) { + delete (id) { // find index of object that should be deleted - var i, - deleteAtIndex; + let deleteAtIndex; - for (i = 0; i < this.values.length; i += 1) { + for (let i = 0; i < this.values.length; i += 1) { if (this.values[i][this.id] === id) { deleteAtIndex = i; break; @@ -71,23 +67,23 @@ app.factory('Resource', function () { if (this.hashMap[id] !== undefined) { delete this.hashMap[id]; } - }, + } - clear: function () { + clear () { this.hashMap = {}; - // http://stackoverflow.com/questions/1232040/how-to-empty-an-array-in-javascript - // this is the fastes way to empty an array when you want to keep the - // reference around + // http://stackoverflow.com/questions/1232040 + // this is the fastes way to empty an array when you want to keep + // the reference around while (this.values.length > 0) { this.values.pop(); } - }, + } - getAll: function () { + getAll () { return this.values; } - }; + } return Resource; });
\ No newline at end of file diff --git a/js/service/Settings.js b/js/service/Settings.js index 09a89f6ed..61e79b25d 100644 --- a/js/service/Settings.js +++ b/js/service/Settings.js @@ -12,20 +12,17 @@ app.service('Settings', function () { this.settings = {}; - this.receive = function (data) { - var key; - for (key in data) { - if (data.hasOwnProperty(key)) { - this.settings[key] = data[key]; - } + this.receive = (data) => { + for (let key in data) { + this.settings[key] = data[key]; } }; - this.get = function (key) { + this.get = (key) => { return this.settings[key]; }; - this.set = function (key, value) { + this.set = (key, value) => { this.settings[key] = value; }; |