@thepassle/app-tools 0.8.8 → 0.8.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/index.js +10 -3
- package/package.json +1 -1
- package/router/index.js +9 -4
package/api/index.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { createLogger } from '../utils/log.js';
|
|
2
2
|
const log = createLogger('api');
|
|
3
3
|
|
|
4
|
+
class StatusError extends Error {
|
|
5
|
+
constructor(response) {
|
|
6
|
+
super(response.statusText);
|
|
7
|
+
this.response = response;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
4
11
|
function handleStatus(response) {
|
|
5
12
|
if (!response.ok) {
|
|
6
|
-
log('Response not ok', response
|
|
7
|
-
throw new
|
|
13
|
+
log('Response not ok', response);
|
|
14
|
+
throw new StatusError(response);
|
|
8
15
|
}
|
|
9
16
|
return response;
|
|
10
17
|
}
|
|
@@ -137,7 +144,7 @@ export class Api {
|
|
|
137
144
|
/** [PLUGINS - HANDLEERROR] */
|
|
138
145
|
.catch(async e => {
|
|
139
146
|
log(`Fetch failed ${method} ${url}`, e);
|
|
140
|
-
const shouldThrow = (await Promise.all(plugins.map(({handleError}) => handleError?.(e) ??
|
|
147
|
+
const shouldThrow = plugins.length === 0 || (await Promise.all(plugins.map(({ handleError }) => handleError?.(e) ?? true))).every(_ => !!_);
|
|
141
148
|
if(shouldThrow) throw e;
|
|
142
149
|
});
|
|
143
150
|
}
|
package/package.json
CHANGED
package/router/index.js
CHANGED
|
@@ -106,7 +106,7 @@ export class Router extends EventTarget {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
_onPopState = () => {
|
|
109
|
-
this.navigate(new URL(window.location.href));
|
|
109
|
+
this.navigate(new URL(window.location.href), { backNav: true });
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
_onAnchorClick = (e) => {
|
|
@@ -137,9 +137,12 @@ export class Router extends EventTarget {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
/**
|
|
140
|
-
* @param {string | URL} url
|
|
140
|
+
* @param {string | URL} url The URL to navigate to.
|
|
141
|
+
* @param {@param {{
|
|
142
|
+
* backNav?: boolean
|
|
143
|
+
* }} options} options An options object to configure the navigation. The backNav property specifies whether the navigation is a backward navigation, which doesn't push the navigation into browser nav history.
|
|
141
144
|
*/
|
|
142
|
-
async navigate(url) {
|
|
145
|
+
async navigate(url, options = {}) {
|
|
143
146
|
if (typeof url === 'string') {
|
|
144
147
|
url = new URL(url, this.baseUrl);
|
|
145
148
|
}
|
|
@@ -183,7 +186,9 @@ export class Router extends EventTarget {
|
|
|
183
186
|
}
|
|
184
187
|
}
|
|
185
188
|
|
|
186
|
-
|
|
189
|
+
if (!options.backNav) {
|
|
190
|
+
window.history.pushState(null, '', `${url.pathname}${url.search}`);
|
|
191
|
+
}
|
|
187
192
|
document.title = this.context.title;
|
|
188
193
|
this._notifyUrlChanged();
|
|
189
194
|
|