Skip to content

Commit 222e655

Browse files
committed
๐Ÿ›  add response argument to error & append events
๐Ÿ›  add fetchPromise argument to request event
1 parent d2a09d1 commit 222e655

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

โ€Žjs/page-load.jsโ€Ž

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,10 @@ proto.loadNextPage = function() {
5252
this.isLoading = true;
5353
if ( typeof fetchOptions == 'function' ) fetchOptions = fetchOptions();
5454

55-
// TODO add fetch options
5655
let fetchPromise = fetch( path, fetchOptions ).then( ( response ) => {
5756
if ( !response.ok ) {
5857
let error = new Error( response.statusText );
59-
this.onPageError( error, path );
58+
this.onPageError( error, path, response );
6059
return { response };
6160
}
6261

@@ -74,7 +73,7 @@ proto.loadNextPage = function() {
7473
} );
7574
} );
7675

77-
this.dispatchEvent( 'request', null, [ path ] );
76+
this.dispatchEvent( 'request', null, [ path, fetchPromise ] );
7877

7978
return fetchPromise;
8079
};
@@ -108,7 +107,7 @@ proto.appendNextPage = function( body, path, response ) {
108107
let appendReady = () => {
109108
this.appendItems( items, fragment );
110109
this.isLoading = false;
111-
this.dispatchEvent( 'append', null, [ body, path, items ] );
110+
this.dispatchEvent( 'append', null, [ body, path, items, response ] );
112111
return promiseValue;
113112
};
114113

@@ -215,10 +214,10 @@ proto.lastPageReached = function( body, path ) {
215214

216215
// ----- error ----- //
217216

218-
proto.onPageError = function( error, path ) {
217+
proto.onPageError = function( error, path, response ) {
219218
this.isLoading = false;
220219
this.canLoad = false;
221-
this.dispatchEvent( 'error', null, [ error, path ] );
220+
this.dispatchEvent( 'error', null, [ error, path, response ] );
222221
return error;
223222
};
224223

0 commit comments

Comments
ย (0)