1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { set } from "https://esm.town/v/std/set?v=11";
import { PUBLIC_STATE } from "https://esm.town/v/joey/PUBLIC_STATE";
export const setPublicState = async (key: string, value: any) => {
const keys = key.split("/");
let current = PUBLIC_STATE;
for (let i = 0; i < keys.length - 1; i++) {
const key = keys[i];
if (!current[key]) {
current[key] = {};
}
current = current[key];
}
current[keys[keys.length - 1]] = value;
await set("PUBLIC_STATE", PUBLIC_STATE);
};
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!
October 23, 2023