Public
Script
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
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
let { __state } = await import("https://esm.town/v/abc3354/__state");
// not working yet, didn't manage to affect dynamic value to @me.__state
export const state = function (
id: string,
defaultValue: { [key: string]: any }
): { [key: string]: any } {
if (__state == null) {
__state = {};
}
if (__state[id] == null) {
__state = {
...__state,
[id]: defaultValue,
};
}
return [
__state[id],
function (newState) {
const newStore = {
...__state,
[id]: newState,
};
__state = newStore;
},
];
return state;
};
October 23, 2023