From ffd0258a7cef9f5ba0851925aa03de7688175453 Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Thu, 29 Aug 2013 06:36:48 +0100 Subject: [PATCH] call the requestFinished hook in the new request handling code - for plugins that need it also make a request to hook something that doesn't exist a non-fatal error - to reduce plugin breakage for removed hooks --- code/hooks.js | 9 +++++++-- code/map_data_request.js | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/code/hooks.js b/code/hooks.js index e0633691..629c5ff3 100644 --- a/code/hooks.js +++ b/code/hooks.js @@ -43,7 +43,8 @@ // array [GUID, time, details]. Plugin can manipulate the // array to change order or add additional values to the // details of a portal. -// requestFinished: called after each request finished. Argument is +// requestFinished: DEPRECATED: best to use mapDataRefreshEnd instead +// called after each map data request finished. Argument is // {success: boolean} indicated the request success or fail. // iitcLoaded: called after IITC and all plugins loaded @@ -72,7 +73,11 @@ window.runHooks = function(event, data) { window.addHook = function(event, callback) { - if(VALID_HOOKS.indexOf(event) === -1) throw('Unknown event type: ' + event); + if(VALID_HOOKS.indexOf(event) === -1) { + console.error('addHook: Unknown event type: ' + event + ' - ignoring'); + return; + } + if(typeof callback !== 'function') throw('Callback must be a function.'); if(!_hooks[event]) diff --git a/code/map_data_request.js b/code/map_data_request.js index 4c839407..3b37eb1b 100644 --- a/code/map_data_request.js +++ b/code/map_data_request.js @@ -368,6 +368,9 @@ window.MapDataRequest.prototype.handleResponse = function (data, tiles, success) var id = tiles[i]; this.requeueTile(id, true); } + + window.runHooks('requestFinished', {success: false}); + } else { // TODO: use result.minLevelOfDetail ??? stock site doesn't use it yet... @@ -407,6 +410,8 @@ window.MapDataRequest.prototype.handleResponse = function (data, tiles, success) } } + + window.runHooks('requestFinished', {success: true}); } this.processRequestQueue();