turbo-web 4.2.9 → 4.2.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/dist/turbo.js +24 -20
- package/package.json +1 -1
package/dist/turbo.js
CHANGED
|
@@ -687,6 +687,29 @@ class NoopRouter {
|
|
|
687
687
|
unsubscribe() {}
|
|
688
688
|
}
|
|
689
689
|
|
|
690
|
+
class TurboHTTP {
|
|
691
|
+
constructor(baseURL = '') {
|
|
692
|
+
this.baseURL = baseURL;
|
|
693
|
+
}
|
|
694
|
+
#buildUrl(endpoint) {
|
|
695
|
+
return endpoint.startsWith('http') ? endpoint : `${this.baseURL}${endpoint}`;
|
|
696
|
+
}
|
|
697
|
+
async get(endpoint) {
|
|
698
|
+
const response = await fetch(`${this.baseURL}${endpoint}`);
|
|
699
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
700
|
+
return response.json();
|
|
701
|
+
}
|
|
702
|
+
async post(endpoint, payload) {
|
|
703
|
+
const response = await fetch(`${this.baseURL}${endpoint}`, {
|
|
704
|
+
method: 'POST',
|
|
705
|
+
headers: { 'Content-Type': 'application/json' },
|
|
706
|
+
body: JSON.stringify(payload)
|
|
707
|
+
});
|
|
708
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
709
|
+
return response.json();
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
|
|
690
713
|
function createApp(RootComponent, props = {}, options = {}) {
|
|
691
714
|
let parentEl = null;
|
|
692
715
|
let isMounted = false;
|
|
@@ -694,6 +717,7 @@ function createApp(RootComponent, props = {}, options = {}) {
|
|
|
694
717
|
const context = {
|
|
695
718
|
router: options.router || new NoopRouter(),
|
|
696
719
|
store: options.store || null,
|
|
720
|
+
http: options.http || new TurboHTTP(),
|
|
697
721
|
};
|
|
698
722
|
function reset() {
|
|
699
723
|
parentEl = null;
|
|
@@ -1252,24 +1276,4 @@ class Store {
|
|
|
1252
1276
|
}
|
|
1253
1277
|
}
|
|
1254
1278
|
|
|
1255
|
-
class TurboHTTP {
|
|
1256
|
-
constructor(baseURL = '') {
|
|
1257
|
-
this.baseURL = baseURL;
|
|
1258
|
-
}
|
|
1259
|
-
async get(endpoint) {
|
|
1260
|
-
const response = await fetch(`${this.baseURL}${endpoint}`);
|
|
1261
|
-
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
1262
|
-
return response.json();
|
|
1263
|
-
}
|
|
1264
|
-
async post(endpoint, payload) {
|
|
1265
|
-
const response = await fetch(`${this.baseURL}${endpoint}`, {
|
|
1266
|
-
method: 'POST',
|
|
1267
|
-
headers: { 'Content-Type': 'application/json' },
|
|
1268
|
-
body: JSON.stringify(payload)
|
|
1269
|
-
});
|
|
1270
|
-
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
1271
|
-
return response.json();
|
|
1272
|
-
}
|
|
1273
|
-
}
|
|
1274
|
-
|
|
1275
1279
|
export { DOM_TYPES, HashRouter, RouterLink, RouterOutlet, Store, TurboHTTP, createApp, defineComponent, h, hFragment, hSlot, hString, nextTick };
|