feat: support passing signals as island props (#757)

This commit adds support for passing signals to islands in component
props. This is useful for passing around mutable state between islands.
The signal's value needs to be serializable for this to work.
This commit is contained in:
Luca Casonato
2023-05-31 10:29:46 +02:00
committed by GitHub
parent a6852fa58f
commit e3f9a0df08
11 changed files with 136 additions and 13 deletions
+9 -1
View File
@@ -257,10 +257,18 @@ export async function render<Data>(
const url = addImport("/deserializer.js");
script += `import { deserialize } from "${url}";`;
}
if (res.hasSignals) {
const url = addImport("/signals.js");
script += `import { signal } from "${url}";`;
}
script += `const ST = document.getElementById("__FRSH_STATE").textContent;`;
script += `const STATE = `;
if (res.requiresDeserializer) {
script += `deserialize(ST);`;
if (res.hasSignals) {
script += `deserialize(ST, signal);`;
} else {
script += `deserialize(ST);`;
}
} else {
script += `JSON.parse(ST).v;`;
}