From 6f8b6c684b60dce066c7e5bc488f9bde9688d53e Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 7 Aug 2019 15:00:26 -0700 Subject: [PATCH] Api4Ctrl - Fix infinite reloads I noticed that the `afform-html` GUI is sending an infinite number requests to reload its data. After bisecting, I found that e7ebc633a had expanded the scope the `watch()` so that it reloads on *any* change to `affApi4Ctrl` (not just a change in params). But the `affApi4Ctrl` includes the `.result` data - as soon as the result data is returned, it re-triggers the watch and sends the request again. This becomes an infinite loop. I don't think this was necessary for the goal of indexing - although maybe the idea was that a change to `.index` should cause a reload, which seems reasonable. So I've whitelisted fields which deal with APIv4 inputs. --- ext/afform/core/ang/afformCore/Api4Ctrl.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ext/afform/core/ang/afformCore/Api4Ctrl.js b/ext/afform/core/ang/afformCore/Api4Ctrl.js index 67fac36b4d..41648cfc1d 100644 --- a/ext/afform/core/ang/afformCore/Api4Ctrl.js +++ b/ext/afform/core/ang/afformCore/Api4Ctrl.js @@ -40,7 +40,13 @@ var mode = $scope.affApi4Refresh ? $scope.affApi4Refresh : 'auto'; switch (mode) { - case 'auto': $scope.$watch('affApi4Ctrl', ctrl.refresh, true); break; + case 'auto': + // Note: Do NOT watch '.result' or '.loading' - causes infinite reloads. + $scope.$watchCollection('affApi4Ctrl.params', ctrl.refresh, true); + $scope.$watch('affApi4Ctrl.index', ctrl.refresh, true); + $scope.$watch('affApi4Ctrl.entity', ctrl.refresh, true); + $scope.$watch('affApi4Ctrl.action', ctrl.refresh, true); + break; case 'init': ctrl.refresh(); break; case 'manual': break; default: throw 'Unrecognized refresh mode: '+ mode; -- 2.25.1