Readme

⚠️ Deprecated in favor of @stevekrouse/reloadOnSave

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { createElement } from "https://esm.sh/react";
import { getCurrentValVersionNumber } from "https://esm.town/v/stevekrouse/getCurrentValVersionNumber";
import { parentReference } from "https://esm.town/v/stevekrouse/parentReference";
export const reloadOnVals = async function(vals: { userHandle: string; valName: string }[]) {
const valVersions = await Promise.all(vals.map(getCurrentValVersionNumber));
// console.log("initialValVersions: ", valVersions);
const interval = setInterval(async () => {
let newValVersions = await Promise.all(vals.map(getCurrentValVersionNumber));
// console.log("newValVersions: ", newValVersions);
if (JSON.stringify(newValVersions) !== JSON.stringify(valVersions)) {
clearInterval(interval);
window.location.reload();
}
}, 1000);
};
export const ReloadScriptText = (vals = [parentReference()]) =>
`<script type="module">
import { reloadOnVals } from "${import.meta.url}"
reloadOnVals(${JSON.stringify(vals)})
</script>`;
export const ReloadScriptReactElement = ({ vals } = { vals: [parentReference()] }) =>
createElement("script", {
type: "module",
dangerouslySetInnerHTML: {
__html: `import { reloadOnVals } from "${import.meta.url}";
reloadOnVals(${JSON.stringify(vals)});`,
},
});
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
v14
March 25, 2024