Skip to content

Commit

Permalink
fix: fix issue with custom fetch function (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
bill-min committed Sep 1, 2022
1 parent 9ffc57e commit f6b45f8
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div>
Host app
</div>
<script>
$csr_custom_fetch_index_C=(window.$csr_custom_fetch_index_C||[]).concat({"l":1,"w":[["s0-8",0,{},{"f":1}]],"t":["Bj+pRfsl"]})
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div>
Host app
</div>
<div />
<script>
$csr_custom_fetch_index_C=(window.$csr_custom_fetch_index_C||[]).concat({"l":1,"w":[["s0-8",0,{},{"f":1}]],"t":["Bj+pRfsl"]})
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div>
Host app
</div>
<div>
Custom fetch(src: embed) content.
</div>
<script>
$csr_custom_fetch_index_C=(window.$csr_custom_fetch_index_C||[]).concat({"l":1,"w":[["s0-8",0,{},{"f":1}]],"t":["Bj+pRfsl"]})
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div>
Host app
</div>
<div
data-src="embed"
id="GENERATED-0"
>
Custom fetch(src: /embed) content.
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class {
onCreate() {
this.state = { mounted: false };
}
onMount() {
this.state.mounted = true;
}
}

<if(state.mounted)>
<micro-frame src="embed" fetch(src) {
return new Promise(resolve => {
const stream = new ReadableStream({
start(controller) {
const encoder = new TextEncoder();
controller.enqueue(encoder.encode(`Custom fetch(src: ${src}) content.`));
controller.close();
}
});
resolve({ ok: true, body: stream });
});
} />
</if>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<esbuild-assets/>
<div>
Embedded App.
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Example</title>
<esbuild-assets/>
</head>
<body>
<div>Host app</div>
<app/>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<esbuild-assets/>
<div>
Embedded App.
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Example</title>
<esbuild-assets/>
</head>
<body>
<div>Host app</div>
<micro-frame src="embed" fetch(src) {
async function* customFetch() {
yield `Custom fetch(src: ${src}) content.`;
}
return new Promise(resolve => {
resolve({ ok: true, body: customFetch() });
});
} />
</body>
</html>
10 changes: 10 additions & 0 deletions src/components/micro-frame/__tests__/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,13 @@ describe(
describe("csr 404", fixture(path.join(__dirname, "fixtures/csr-404")));

describe("ssr 404", fixture(path.join(__dirname, "fixtures/ssr-404")));

describe(
"csr custom fetch",
fixture(path.join(__dirname, "fixtures/csr-custom-fetch"))
);

describe(
"ssr custom fetch",
fixture(path.join(__dirname, "fixtures/ssr-custom-fetch"))
);
9 changes: 9 additions & 0 deletions src/components/micro-frame/marko-tag.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
}
]
},
"@fetch": {
"type": "function",
"required": false,
"autocomplete": [
{
"description": "Customized fetch function"
}
]
},
"@cache": {
"enum": ["default", "no-store", "reload", "force-cache", "only-if-cached"],
"autocomplete": [
Expand Down

0 comments on commit f6b45f8

Please sign in to comment.