aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <holden.rohrer@gmail.com>2019-12-27 14:57:49 -0500
committerHolden Rohrer <holden.rohrer@gmail.com>2019-12-27 14:57:49 -0500
commit83c956dc71c9fc279eac72ed826f9bd9a36eddc7 (patch)
treedd913cf9313b8969e3053036821df7be31f9b454
parent41f48e065555341f58e4fec73855f4d3b3019f0a (diff)
moved tileHandler in jarvis.js
-rw-r--r--examples/jarvis.js34
1 files changed, 18 insertions, 16 deletions
diff --git a/examples/jarvis.js b/examples/jarvis.js
index 9829c04..9b428e8 100644
--- a/examples/jarvis.js
+++ b/examples/jarvis.js
@@ -34,24 +34,26 @@ function identity(sender){
var read = new Search(search);
var expire = {};
- main.on('tileUpdate', (send, source, tiles) => {
- if (send == sender) return; //this may lead to issues later, but for now is used to count its own updates
- let locs = tilekeys(tiles);
+ main.on('tileUpdate', tileHandler);
+}
+
+function tileHandler(send, source, tiles){
+ if (send == sender) return; //this may lead to issues later, but for now is used to count its own updates
+ let locs = tilekeys(tiles);
- for (let i=0; i<locs.length; i++){
- let loc = locs[i];
- if (read.has(loc)){
- clearTimeout(expire[loc]);
- delete expire[loc];
- read.del(loc);
- }
- let locspace = new Space();
- locspace.fromfetch(tiles, [loc, loc], conform=false);
- let results = read.add(loc, locspace);
- if (results.length > 0) respond(results);
- expire[loc] = setTimeout(() => {read.del(loc)}, 30000);
+ for (let i=0; i<locs.length; i++){
+ let loc = locs[i];
+ if (read.has(loc)){
+ clearTimeout(expire[loc]);
+ delete expire[loc];
+ read.del(loc);
}
- });
+ let locspace = new Space();
+ locspace.fromfetch(tiles, [loc, loc], conform=false);
+ let results = read.add(loc, locspace);
+ if (results.length > 0) respond(results);
+ expire[loc] = setTimeout(() => {read.del(loc)}, 30000);
+ }
}
let response = new Space();