Skip to content

Commit

Permalink
Fix not-a-function errors navigating between pages
Browse files Browse the repository at this point in the history
In some cases, watch listeners inside controllers are called immediately
upon registration with DataService. This leads to not-a-function errors
when function expressions below haven't been evaluated. Use function
statements rather than function expressions to avoid the errors.

Fixes openshift#1855
  • Loading branch information
spadgett committed May 5, 2015
1 parent cecef65 commit eb3b9d2
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 142 deletions.
6 changes: 3 additions & 3 deletions assets/app/scripts/controllers/builds.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ angular.module('openshiftConsole')
Logger.log("buildConfigs (subscribe)", $scope.buildConfigs);
}));

var associateRunningBuildToBuildConfig = function(buildsByBuildConfig) {
function associateRunningBuildToBuildConfig(buildsByBuildConfig) {
var buildConfigBuildsInProgress = {};
angular.forEach(buildsByBuildConfig, function(buildConfigBuilds, buildConfigName) {
buildConfigBuildsInProgress[buildConfigName] = {};
Expand All @@ -78,7 +78,7 @@ angular.module('openshiftConsole')
return buildConfigBuildsInProgress;
};

var updateFilterWarning = function() {
function updateFilterWarning() {
if (!LabelFilter.getLabelSelector().isEmpty() && $.isEmptyObject($scope.builds) && !$.isEmptyObject($scope.unfilteredBuilds)) {
$scope.alerts["builds"] = {
type: "warning",
Expand Down Expand Up @@ -149,4 +149,4 @@ angular.module('openshiftConsole')
$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
});
});
});
6 changes: 3 additions & 3 deletions assets/app/scripts/controllers/deployments.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ angular.module('openshiftConsole')
$scope.emptyMessage = "Loading...";
var watches = [];

var extractPodTemplates = function() {
function extractPodTemplates() {
angular.forEach($scope.deployments, function(deployment, deploymentId){
$scope.podTemplates[deploymentId] = deployment.spec.template;
});
Expand Down Expand Up @@ -52,7 +52,7 @@ angular.module('openshiftConsole')
Logger.log("builds (subscribe)", $scope.builds);
}));

var updateFilterWarning = function() {
function updateFilterWarning() {
if (!LabelFilter.getLabelSelector().isEmpty() && $.isEmptyObject($scope.deployments) && !$.isEmptyObject($scope.unfilteredDeployments)) {
$scope.alerts["deployments"] = {
type: "warning",
Expand All @@ -75,4 +75,4 @@ angular.module('openshiftConsole')
$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
});
});
});
4 changes: 2 additions & 2 deletions assets/app/scripts/controllers/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ angular.module('openshiftConsole')
Logger.log("image streams (subscribe)", $scope.imageStreams);
}));

var updateFilterWarning = function() {
function updateFilterWarning() {
if (!LabelFilter.getLabelSelector().isEmpty() && $.isEmptyObject($scope.imageStreams) && !$.isEmptyObject($scope.unfilteredImageStreams)) {
$scope.alerts["imageStreams"] = {
type: "warning",
Expand All @@ -50,4 +50,4 @@ angular.module('openshiftConsole')
$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
});
});
});
12 changes: 6 additions & 6 deletions assets/app/scripts/controllers/overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ angular.module('openshiftConsole')
}));

// Expects deploymentsByServiceByDeploymentConfig to be up to date
var podRelationships = function() {
function podRelationships() {
$scope.monopodsByService = {"": {}};
$scope.podsByService = {};
$scope.podsByDeployment = {};
Expand Down Expand Up @@ -126,7 +126,7 @@ angular.module('openshiftConsole')
};

// Filter out monopods we know we don't want to see
var showMonopod = function(pod) {
function showMonopod(pod) {
// Hide pods in the Succeeded or Terminated phase since these are run once pods
// that are done
if (pod.status.phase == 'Succeeded' || pod.status.phase == 'Terminated') {
Expand All @@ -149,7 +149,7 @@ angular.module('openshiftConsole')
return true;
};

var deploymentConfigsByService = function() {
function deploymentConfigsByService() {
$scope.deploymentConfigsByService = {"": {}};
angular.forEach($scope.deploymentConfigs, function(deploymentConfig, depName){
var foundMatch = false;
Expand All @@ -170,7 +170,7 @@ angular.module('openshiftConsole')
});
};

var deploymentsByService = function() {
function deploymentsByService() {
var bySvc = $scope.deploymentsByService = {"": {}};
var bySvcByDepCfg = $scope.deploymentsByServiceByDeploymentConfig = {"": {}};

Expand Down Expand Up @@ -244,7 +244,7 @@ angular.module('openshiftConsole')
Logger.log("imageStreams (subscribe)", $scope.imageStreams);
}));

var associateDeploymentConfigTriggersToBuild = function(deploymentConfig, build) {
function associateDeploymentConfigTriggersToBuild(deploymentConfig, build) {
// Make sure we have both a deploymentConfig and a build
if (!deploymentConfig || !build) {
return;
Expand Down Expand Up @@ -322,7 +322,7 @@ angular.module('openshiftConsole')
Logger.log("builds (subscribe)", $scope.builds);
}));

var updateFilterWarning = function() {
function updateFilterWarning() {
if (!LabelFilter.getLabelSelector().isEmpty() && $.isEmptyObject($scope.services) && !$.isEmptyObject($scope.unfilteredServices)) {
$scope.alerts["services"] = {
type: "warning",
Expand Down
4 changes: 2 additions & 2 deletions assets/app/scripts/controllers/pods.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ angular.module('openshiftConsole')
Logger.log("builds (subscribe)", $scope.builds);
}));

var updateFilterWarning = function() {
function updateFilterWarning() {
if (!LabelFilter.getLabelSelector().isEmpty() && $.isEmptyObject($scope.pods) && !$.isEmptyObject($scope.unfilteredPods)) {
$scope.alerts["pods"] = {
type: "warning",
Expand All @@ -67,4 +67,4 @@ angular.module('openshiftConsole')
$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
});
});
});
4 changes: 2 additions & 2 deletions assets/app/scripts/controllers/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ angular.module('openshiftConsole')
Logger.log("routes (subscribe)", $scope.routesByService);
}));

var routesByService = function(routes) {
function routesByService(routes) {
var routeMap = {};
angular.forEach(routes, function(route, routeName){
routeMap[route.serviceName] = routeMap[route.serviceName] || {};
Expand All @@ -41,7 +41,7 @@ angular.module('openshiftConsole')
return routeMap;
};

var updateFilterWarning = function() {
function updateFilterWarning() {
if (!LabelFilter.getLabelSelector().isEmpty() && $.isEmptyObject($scope.services) && !$.isEmptyObject($scope.unfilteredServices)) {
$scope.alerts["services"] = {
type: "warning",
Expand Down
2 changes: 1 addition & 1 deletion assets/app/scripts/services/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ angular.module('openshiftConsole')

// If this is a cached type (immutable types only), ignore the force parameter
if (this._isTypeCached(type) && existingData && existingData.by('metadata.name')[name]) {
return existingData.by('metadata.name')[name];
deferred.resolve(existingData.by('metadata.name')[name]);
}
else if (!force && this._watchInFlight(type, context) && this._resourceVersion(type, context)) {
var obj = existingData.by('metadata.name')[name];
Expand Down
Loading

0 comments on commit eb3b9d2

Please sign in to comment.