refac
This commit is contained in:
1 parent
04fae8b357
commit
47b007ef19
1 file changed
+15
-11
@@ -59,21 +59,25 @@
|
|||||||
tokens = marked.lexer(replaceTokens(processResponseContent(content), model?.name, $user?.name));
|
tokens = marked.lexer(replaceTokens(processResponseContent(content), model?.name, $user?.name));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Throttle parsing to once per animation frame while streaming
|
const updateHandler = (content) => {
|
||||||
$: if (content) {
|
if (content) {
|
||||||
if (done) {
|
if (done) {
|
||||||
cancelAnimationFrame(pendingUpdate);
|
cancelAnimationFrame(pendingUpdate);
|
||||||
pendingUpdate = null;
|
|
||||||
parseTokens();
|
|
||||||
} else if (!pendingUpdate) {
|
|
||||||
pendingUpdate = requestAnimationFrame(() => {
|
|
||||||
pendingUpdate = null;
|
pendingUpdate = null;
|
||||||
parseTokens();
|
parseTokens();
|
||||||
});
|
} else if (!pendingUpdate) {
|
||||||
|
pendingUpdate = requestAnimationFrame(() => {
|
||||||
|
pendingUpdate = null;
|
||||||
|
parseTokens();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
onDestroy(() => {
|
$: updateHandler(content);
|
||||||
|
|
||||||
|
// Throttle parsing to once per animation frame while streaming
|
||||||
|
$: onDestroy(() => {
|
||||||
cancelAnimationFrame(pendingUpdate);
|
cancelAnimationFrame(pendingUpdate);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in new issue
Block a user