From 7d6462b8158b5bfb05402a3da6ecebb6640b3889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 12 Aug 2015 12:30:56 +0200 Subject: [PATCH] Fixed broken GCODE viewer / concurrent settings requests The GCODE viewer settings callback was not properly called, hence the viewer was not initialized properly. Changed prevention of concurrent settings requests to properly handle the situation where the registered settings callbacks might be extended through another callback. --- .../static/js/app/viewmodels/settings.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/octoprint/static/js/app/viewmodels/settings.js b/src/octoprint/static/js/app/viewmodels/settings.js index e6c94354..0c5d4179 100644 --- a/src/octoprint/static/js/app/viewmodels/settings.js +++ b/src/octoprint/static/js/app/viewmodels/settings.js @@ -279,20 +279,25 @@ $(function() { type: "GET", dataType: "json", success: function(response) { - var callbacks = self.callbacks; - self.callbacks = []; - if (callback) { - callbacks.push(callback); + self.callbacks.push(callback); } try { self.fromResponse(response); - _.each(callbacks, function(cb) { - cb(); - }); + + var cb; + while (self.callbacks.length) { + cb = self.callbacks.shift(); + try { + cb(); + } catch(exc) { + log.error("Error calling settings callback", cb, ":", (exc.stack || exc)); + } + } } finally { self.receiving(false); + self.callbacks = []; } }, error: function(xhr) {