-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: refresh sse stream when src update (#15)
* fix: refresh stream when src update * fix: work with same slotId * refactor: refine event handler * test: unit test * refactor: refine code * refactor: fix type * fix: fix function binding
- Loading branch information
Showing
47 changed files
with
529 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,39 @@ | ||
import StreamSource from "../../stream-source/component/StreamSource"; | ||
$ const sourceName = input.from; | ||
$ let err; | ||
import { getOrCreateStreamSource } from "../../stream-source/component/helper"; | ||
|
||
$ { | ||
if (!out.global.STREAM_SOURCE_MAP_SERVER || !out.global.STREAM_SOURCE_MAP_SERVER.has(sourceName)) | ||
err = new Error(`micro-frame-sse ${sourceName} is not defined.`); | ||
const streamSource = getOrCreateStreamSource(input.from, out); | ||
const stream = streamSource.slot(input.slot); | ||
let finishLoading; | ||
const loadingPromise = | ||
input.loading && new Promise((res) => (finishLoading = res)); | ||
} | ||
|
||
<if(err)> | ||
$ if (!input.catch) throw err; | ||
<${input.catch}(err)/> | ||
</if> | ||
<else> | ||
$ const streamSource = out.global.STREAM_SOURCE_MAP_SERVER.get(sourceName); | ||
$ const stream = streamSource.slot(input.slot); | ||
$ let finishLoading; | ||
$ { | ||
const loadingPromise = | ||
input.loading && new Promise((res) => (finishLoading = res)); | ||
} | ||
<div id=component.id data-slot=input.slot data-from=input.from> | ||
<macro name="wait"> | ||
<await(stream.next()) | ||
client-reorder=input.clientReorder | ||
timeout=input.timeout | ||
> | ||
<@then|{ value, done }|> | ||
<if(!done)> | ||
$!{value} | ||
<wait/> | ||
</if> | ||
<else> | ||
$ finishLoading && finishLoading(); | ||
</else> | ||
</@then> | ||
<@catch|e|> | ||
<div id=component.id data-slot=input.slot data-from=input.from> | ||
<macro name="wait"> | ||
<await(stream.next()) | ||
client-reorder=input.clientReorder | ||
timeout=input.timeout | ||
> | ||
<@then|{ value, done }|> | ||
<if(!done)> | ||
$!{value} | ||
<wait/> | ||
</if> | ||
<else> | ||
$ finishLoading && finishLoading(); | ||
<${input.catch}(e)/> | ||
</@catch> | ||
</await> | ||
</macro> | ||
$ out.bf("@_", component, true); | ||
<if(stream)> | ||
<if(input.loading)> | ||
<await(loadingPromise) placeholder=input.loading client-reorder/> | ||
</if> | ||
<wait/> | ||
</else> | ||
</@then> | ||
<@catch|e|> | ||
$ finishLoading && finishLoading(); | ||
<${input.catch}(e)/> | ||
</@catch> | ||
</await> | ||
</macro> | ||
$ out.bf("@_", component, true); | ||
<if(stream)> | ||
<if(input.loading)> | ||
<await(loadingPromise) placeholder=input.loading client-reorder/> | ||
</if> | ||
$ out.ef(); | ||
</div> | ||
</else> | ||
<wait/> | ||
</if> | ||
$ out.ef(); | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
...ts__/__snapshots__/micro-frame-sse/csr-invalid-sourcename/renders.expected/loading.0.html
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
...ts__/__snapshots__/micro-frame-sse/csr-invalid-sourcename/renders.expected/loading.1.html
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
...ts__/__snapshots__/micro-frame-sse/csr-invalid-sourcename/renders.expected/loading.2.html
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
...tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/loading.0.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div> | ||
Host app | ||
</div> | ||
<button> | ||
Change | ||
</button> | ||
<script> | ||
$csr_then_change_src_index_C=(window.$csr_then_change_src_index_C||[]).concat({"l":1,"w":[["s0-8",0,{},{"f":1}]],"t":["hjKmUtFR"]}) | ||
</script> |
12 changes: 12 additions & 0 deletions
12
...tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/loading.1.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<div> | ||
Host app | ||
</div> | ||
<button> | ||
Change | ||
</button> | ||
<div /> | ||
<div /> | ||
<div /> | ||
<script> | ||
$csr_then_change_src_index_C=(window.$csr_then_change_src_index_C||[]).concat({"l":1,"w":[["s0-8",0,{},{"f":1}]],"t":["hjKmUtFR"]}) | ||
</script> |
16 changes: 16 additions & 0 deletions
16
...tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/loading.2.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<div> | ||
Host app | ||
</div> | ||
<button> | ||
Change | ||
</button> | ||
<div /> | ||
<div> | ||
<p> | ||
test_html for slot_1 | ||
</p> | ||
</div> | ||
<div /> | ||
<script> | ||
$csr_then_change_src_index_C=(window.$csr_then_change_src_index_C||[]).concat({"l":1,"w":[["s0-8",0,{},{"f":1}]],"t":["hjKmUtFR"]}) | ||
</script> |
20 changes: 20 additions & 0 deletions
20
...tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/loading.3.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<div> | ||
Host app | ||
</div> | ||
<button> | ||
Change | ||
</button> | ||
<div /> | ||
<div> | ||
<p> | ||
test_html for slot_1 | ||
</p> | ||
</div> | ||
<div> | ||
<p> | ||
test_html for slot_2 | ||
</p> | ||
</div> | ||
<script> | ||
$csr_then_change_src_index_C=(window.$csr_then_change_src_index_C||[]).concat({"l":1,"w":[["s0-8",0,{},{"f":1}]],"t":["hjKmUtFR"]}) | ||
</script> |
21 changes: 21 additions & 0 deletions
21
...tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/loading.4.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<div> | ||
Host app | ||
</div> | ||
<button> | ||
Change | ||
</button> | ||
<div /> | ||
<div> | ||
<p> | ||
test_html for slot_1 | ||
</p> | ||
next chunk for slot_1 | ||
</div> | ||
<div> | ||
<p> | ||
test_html for slot_2 | ||
</p> | ||
</div> | ||
<script> | ||
$csr_then_change_src_index_C=(window.$csr_then_change_src_index_C||[]).concat({"l":1,"w":[["s0-8",0,{},{"f":1}]],"t":["hjKmUtFR"]}) | ||
</script> |
12 changes: 12 additions & 0 deletions
12
..._tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/step-0.0.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<div> | ||
Host app | ||
</div> | ||
<button> | ||
Change | ||
</button> | ||
<div /> | ||
<div /> | ||
<div /> | ||
<script> | ||
$csr_then_change_src_index_C=(window.$csr_then_change_src_index_C||[]).concat({"l":1,"w":[["s0-8",0,{},{"f":1}]],"t":["hjKmUtFR"]}) | ||
</script> |
16 changes: 16 additions & 0 deletions
16
..._tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/step-0.1.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<div> | ||
Host app | ||
</div> | ||
<button> | ||
Change | ||
</button> | ||
<div /> | ||
<div> | ||
<p> | ||
test_html for slot_1 | ||
</p> | ||
</div> | ||
<div /> | ||
<script> | ||
$csr_then_change_src_index_C=(window.$csr_then_change_src_index_C||[]).concat({"l":1,"w":[["s0-8",0,{},{"f":1}]],"t":["hjKmUtFR"]}) | ||
</script> |
20 changes: 20 additions & 0 deletions
20
..._tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/step-0.2.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<div> | ||
Host app | ||
</div> | ||
<button> | ||
Change | ||
</button> | ||
<div /> | ||
<div> | ||
<p> | ||
test_html for slot_1 | ||
</p> | ||
</div> | ||
<div> | ||
<p> | ||
test_html for slot_2 | ||
</p> | ||
</div> | ||
<script> | ||
$csr_then_change_src_index_C=(window.$csr_then_change_src_index_C||[]).concat({"l":1,"w":[["s0-8",0,{},{"f":1}]],"t":["hjKmUtFR"]}) | ||
</script> |
21 changes: 21 additions & 0 deletions
21
..._tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/step-0.3.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<div> | ||
Host app | ||
</div> | ||
<button> | ||
Change | ||
</button> | ||
<div /> | ||
<div> | ||
<p> | ||
test_html for slot_1 | ||
</p> | ||
after src change | ||
</div> | ||
<div> | ||
<p> | ||
test_html for slot_2 | ||
</p> | ||
</div> | ||
<script> | ||
$csr_then_change_src_index_C=(window.$csr_then_change_src_index_C||[]).concat({"l":1,"w":[["s0-8",0,{},{"f":1}]],"t":["hjKmUtFR"]}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.