From 6a41b18ba78092a433e0b379b9ef7e739ab14715 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 28 Jun 2020 17:07:12 -0700 Subject: [PATCH] Dedent by using early returns. --- frontends/ycdl_flask/static/js/common.js | 32 +++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/frontends/ycdl_flask/static/js/common.js b/frontends/ycdl_flask/static/js/common.js index 5c67f7d..7d96bea 100644 --- a/frontends/ycdl_flask/static/js/common.js +++ b/frontends/ycdl_flask/static/js/common.js @@ -12,22 +12,26 @@ function _request(method, url, callback) request.onreadystatechange = function() { - if (request.readyState == 4) + if (request.readyState != 4) { - if (callback != null) - { - if (request.status != 0) - { - response.completed = true; - response.data = JSON.parse(request.responseText); - } - response.meta = { - "request_url": url, - "status": request.status - } - callback(response); - } + return; } + + if (callback == null) + { + return; + } + + if (request.status != 0) + { + response.completed = true; + response.data = JSON.parse(request.responseText); + } + response.meta = { + "request_url": url, + "status": request.status + } + callback(response); }; var asynchronous = true; request.open(method, url, asynchronous);