From 222e65595dd25a5b327afb20f64a0a40c78ce81b Mon Sep 17 00:00:00 2001 From: Dave DeSandro Date: Thu, 31 Dec 2020 21:11:33 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=20add=20response=20argument=20to?= =?UTF-8?q?=20error=20&=20append=20events?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🛠 add fetchPromise argument to request event --- js/page-load.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/js/page-load.js b/js/page-load.js index b101942..a9a5d04 100644 --- a/js/page-load.js +++ b/js/page-load.js @@ -52,11 +52,10 @@ proto.loadNextPage = function() { this.isLoading = true; if ( typeof fetchOptions == 'function' ) fetchOptions = fetchOptions(); - // TODO add fetch options let fetchPromise = fetch( path, fetchOptions ).then( ( response ) => { if ( !response.ok ) { let error = new Error( response.statusText ); - this.onPageError( error, path ); + this.onPageError( error, path, response ); return { response }; } @@ -74,7 +73,7 @@ proto.loadNextPage = function() { } ); } ); - this.dispatchEvent( 'request', null, [ path ] ); + this.dispatchEvent( 'request', null, [ path, fetchPromise ] ); return fetchPromise; }; @@ -108,7 +107,7 @@ proto.appendNextPage = function( body, path, response ) { let appendReady = () => { this.appendItems( items, fragment ); this.isLoading = false; - this.dispatchEvent( 'append', null, [ body, path, items ] ); + this.dispatchEvent( 'append', null, [ body, path, items, response ] ); return promiseValue; }; @@ -215,10 +214,10 @@ proto.lastPageReached = function( body, path ) { // ----- error ----- // -proto.onPageError = function( error, path ) { +proto.onPageError = function( error, path, response ) { this.isLoading = false; this.canLoad = false; - this.dispatchEvent( 'error', null, [ error, path ] ); + this.dispatchEvent( 'error', null, [ error, path, response ] ); return error; };