POC: DO NOT USE THIS
A svelte preprocessor that takes a function call that is assigned to a value in a reactive declaration and delegates that work to a web worker.
<script context="module">
import marked from "marked";
export function parse(source) {
if (!source) return;
return marked(source);
}
</script>
<script>
import { markdown } from "./markdown.js";
worker: text = parse(markdown);
</script>
This preprocessor only supports the simple assignment of a call expression (x = some_func(val)
), it does not support any kind of boolean expression typical of reactive declarations (x = y && some_func(val)
).
Any function that is delegated to a worker must be exported from the module script. The worker is inlined and not written to a separate file (new Worker(URL.createObjectURL(new Blob([src])))
). The preprocessor bundles for now but could make use of type: module
workers, support was only recently added to chrome so this may not be feasible for some time.
There are many questions.
The implementation is very rough.
Do not use this.