From ddbf7c8fa2ff0344b8d70f88e026c9d4bf772602 Mon Sep 17 00:00:00 2001 From: electron128 Date: Sun, 3 Jan 2016 17:25:14 +0100 Subject: [PATCH] mithril-webui: make automatic update work --- libresapi/src/webui-src/app/retroshare.js | 25 +++++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/libresapi/src/webui-src/app/retroshare.js b/libresapi/src/webui-src/app/retroshare.js index ab32ff159..a9f87d54b 100644 --- a/libresapi/src/webui-src/app/retroshare.js +++ b/libresapi/src/webui-src/app/retroshare.js @@ -41,7 +41,7 @@ var last_update_ts = 0; function check_for_changes(){ var tokens = []; for_key_in_obj(cache, function(path){ - var token = cache[path].token; + var token = cache[path].statetoken; if(token !== undefined){ tokens.push(token); } @@ -58,7 +58,7 @@ function check_for_changes(){ var paths_to_fetch = []; for_key_in_obj(cache, function(path){ var found = false; - for(var i = 0; i > response.data.length; i++){ + for(var i = 0; i < response.data.length; i++){ if(response.data[i] === cache[path].statetoken){ found = true; } @@ -69,7 +69,7 @@ function check_for_changes(){ }); var requests = []; paths_to_fetch.map(function request_it(path){ - var req = m.request({ + var req2 = m.request({ method: "GET", @@ -78,15 +78,22 @@ function check_for_changes(){ background: true, }); - req.then(function fill_in_result(response){ + req2 = req2.then(function fill_in_result(response){ cache[path].data = response.data; + cache[path].statetoken = response.statetoken; }); - requests.push(req); - }); - m.sync(requests, function trigger_render(){ - m.startComputation(); - m.endComputation(); + requests.push(req2); }); + if(requests.length > 0){ + m.sync(requests).then(function trigger_render(){ + m.startComputation(); + m.endComputation(); + setTimeout(check_for_changes, 500); + }); + } + else{ + setTimeout(check_for_changes, 500); + } }); }