export const Form = { id: 'Form', init() { // Get states. app.state.selected = app.getState('selected') ?? []; app.state.agreed = app.getState('agreed') ?? 'Select item.'; }, render() { return `
Agreed to: ${app.state.agreed}
Selected: ${app.state.selected}
`; }, } const fun1 = () => { globalThis.reactiveRadio = (value) => { let counterElement = document.querySelector('#agreed'); counterElement.textContent = value; // Update state app.setState({ agreed: value }, Form.id, true); } }; const fun2 = () => { globalThis.reactiveChecked = (value, checked) => { app.state.selected = checked ? [...new Set([...app.state.selected, value])]: app.state.selected.filter(item => item !== value); document.querySelector('#foods').textContent = app.state.selected.join(', '); // Update state app.setState({ selected: app.state.selected }, Form.id, true); }; }; // Subscribe app.setFun(fun1); app.setFun(fun2);