Skip to content

Commit

Permalink
πŸ›  add response argument to error & append events
Browse files Browse the repository at this point in the history
πŸ›  add fetchPromise argument to request event
  • Loading branch information
desandro committed Jan 1, 2021
1 parent d2a09d1 commit 222e655
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions js/page-load.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

Expand All @@ -74,7 +73,7 @@ proto.loadNextPage = function() {
} );
} );

this.dispatchEvent( 'request', null, [ path ] );
this.dispatchEvent( 'request', null, [ path, fetchPromise ] );

return fetchPromise;
};
Expand Down Expand Up @@ -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;
};

Expand Down Expand Up @@ -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;
};

Expand Down

0 comments on commit 222e655

Please sign in to comment.