From aaa4905e11dbe8d368c8d36078154dbdaeb55b4b Mon Sep 17 00:00:00 2001 From: Alvaro Garcia Date: Mon, 16 Nov 2015 15:07:29 +0100 Subject: [PATCH 1/4] replace type of for loop --- js/cuore/Cuore.Bus.js | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/js/cuore/Cuore.Bus.js b/js/cuore/Cuore.Bus.js index bb91f5c..046f1ef 100644 --- a/js/cuore/Cuore.Bus.js +++ b/js/cuore/Cuore.Bus.js @@ -25,16 +25,14 @@ CUORE.Bus = (function(undefined) { } function unsubscribe(subscriber, events) { - var i; - if (typeof events == "string") { _removeSubscription(_createSubscription(subscriber, events)); return; } - for (i = 0; i < events.length; i++) { - _removeSubscription(_createSubscription(subscriber, events[i])); - } + events.forEach(function (event) { + _removeSubscription(_createSubscription(subscriber, event)); + }); } function hasSubscriptions() { @@ -42,31 +40,28 @@ CUORE.Bus = (function(undefined) { } function subscribers(theEvent) { - var selectedSubscribers = [], - i, subscription, - len = subscriptions.length; + var selectedSubscribers = []; - for (i = 0; i < len; i++) { - subscription = subscriptions[i]; + subscriptions.forEach(function (subscription) { if (subscription.eventName === theEvent) { selectedSubscribers.push(subscription.subscriber); } - } + }); + return selectedSubscribers; } function emit(eventName, params) { - var subscribersList = this.subscribers(eventName), - i, len = subscribersList.length; + var subscribersList = this.subscribers(eventName); debug("Bus.emit (event, params)"); debug(eventName); debug(params); debug("------------"); - for (i = 0; i < len; i++) { - subscribersList[i].eventDispatch(eventName, params); - } + subscribersList.forEach(function (current) { + current.eventDispatch(eventName, params); + }); } function debug(object) { From c2c5809845f0fd55837711b161ea89ede35b1462 Mon Sep 17 00:00:00 2001 From: Alvaro Garcia Date: Mon, 16 Nov 2015 15:13:29 +0100 Subject: [PATCH 2/4] refactor: move javascript idiom deeper --- js/cuore/Cuore.Bus.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/js/cuore/Cuore.Bus.js b/js/cuore/Cuore.Bus.js index 046f1ef..5070b2c 100644 --- a/js/cuore/Cuore.Bus.js +++ b/js/cuore/Cuore.Bus.js @@ -95,12 +95,16 @@ CUORE.Bus = (function(undefined) { for (i = 0; i < len; i++) { if (theSubscription.equals(subscriptions[i])) { - subscriptions.splice(i, 1); + this._removeAt(subscriptions, i); return; } } } + function _removeAt (index, array) { + array.splice(index, 1); + } + function _validSubscriber(subscriber) { return subscriber.eventDispatch; } From d1a71316604284f5c4648d2d5164da5621cad5eb Mon Sep 17 00:00:00 2001 From: Alvaro Garcia Date: Mon, 16 Nov 2015 15:18:53 +0100 Subject: [PATCH 3/4] refactor: remove magic number --- js/cuore/Cuore.Journey.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/js/cuore/Cuore.Journey.js b/js/cuore/Cuore.Journey.js index b30db63..e5707a0 100644 --- a/js/cuore/Cuore.Journey.js +++ b/js/cuore/Cuore.Journey.js @@ -2,11 +2,14 @@ CUORE.Journey = CUORE.Class(null, { init: function(start, end) { var allValues = (start && end); + var minutesInADay; this.itsGranularity = 60; this.minutesInAnHour = 60; + minutesInADay = 24 * this.minutesInAnHour; + this.start = (allValues) ? this._convertToMinutesDay(start) : 0; - this.end = (allValues) ? this._convertToMinutesDay(end) : 1440; + this.end = (allValues) ? this._convertToMinutesDay(end) : minutesInADay; }, starts: function() { From 0b21a0a4b82028d5a3aeedf09737a080cf51df00 Mon Sep 17 00:00:00 2001 From: Alvaro Garcia Date: Mon, 16 Nov 2015 15:24:18 +0100 Subject: [PATCH 4/4] rename files --- index.html | 4 ++-- js/new_cuore/{Cuore.Service.js => Service.js} | 0 js/new_cuore/{Cuore.Services.Label.js => Services.Label.js} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename js/new_cuore/{Cuore.Service.js => Service.js} (100%) rename js/new_cuore/{Cuore.Services.Label.js => Services.Label.js} (100%) diff --git a/index.html b/index.html index a2f56b7..2437cfb 100644 --- a/index.html +++ b/index.html @@ -85,8 +85,8 @@

This is a proposal

- - + + diff --git a/js/new_cuore/Cuore.Service.js b/js/new_cuore/Service.js similarity index 100% rename from js/new_cuore/Cuore.Service.js rename to js/new_cuore/Service.js diff --git a/js/new_cuore/Cuore.Services.Label.js b/js/new_cuore/Services.Label.js similarity index 100% rename from js/new_cuore/Cuore.Services.Label.js rename to js/new_cuore/Services.Label.js