Skip to content

Commit a5b2d70

Browse files
author
Nicholas Thomson
committed
Learn how to defer things...
1 parent 57c277c commit a5b2d70

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

app/scripts/controllers/crunchinator.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,30 @@ angular.module('crunchinatorApp.controllers')
6767
//Bind component data services to the scope, so we can use them in the views
6868
$scope.ComponentData = ComponentData;
6969

70-
var deferred = $q.defer();
71-
function applyFilters() {
72-
_.delay(function(){
73-
$scope.$apply(function() {
74-
Company.runFilters(filterData);
75-
Category.runFilters(filterData);
76-
Investor.runFilters(filterData);
7770

78-
deferred.resolve('Finished filters');
79-
});
80-
}, 300);
81-
82-
return deferred.promise;
83-
}
8471

8572
//All of our filters broadcast 'filterAction' when they've been operated on
8673
//When a filter receives input we set up filterData and run each model's filters
8774
//This should automatically update all the graph displays
8875
$scope.$on('filterAction', function() {
76+
77+
var deferred = $q.defer();
78+
function applyFilters() {
79+
_.delay(function(){
80+
$scope.$apply(function() {
81+
Company.runFilters(filterData);
82+
Category.runFilters(filterData);
83+
Investor.runFilters(filterData);
84+
85+
deferred.resolve('Finished filters');
86+
});
87+
}, 250);
88+
89+
return deferred.promise;
90+
}
91+
8992
$scope.loading = true;
93+
9094
filterData.categoryIds = _.pluck($scope.selectedCategories, 'id');
9195
filterData.companyIds = _.pluck($scope.selectedCompanies, 'id');
9296
filterData.investorIds = _.pluck($scope.selectedInvestors, 'id');

app/scripts/services/model.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ angular.module('crunchinatorApp.models').service('Model', function($rootScope, $
9898
* @return {boolean} whether the number list contains a value within the range
9999
*/
100100
Model.prototype.fallsWithinRange = function(items, range) {
101-
if(items.length === 0) { return false; }
102101
if(range.length === 0) { return true; }
102+
if(items.length === 0) { return false; }
103103

104104

105105
for(var i = 0; i < items.length; i++) {

0 commit comments

Comments
 (0)