setup action signature (state, event)

This commit is contained in:
Geoff Doty 2024-05-05 15:04:45 -04:00
parent c996aac35a
commit 21f4c4344d
1 changed files with 19 additions and 5 deletions

View File

@ -23,17 +23,31 @@ export default function app(opts) {
return data; return data;
} }
// starts app
function dispatch(input, actions) {
Object.entries(actions).forEach(([name, action]) => {
if (typeof action === "function") {
actions[name] = (...args) => {
// update date from action return
Object.assign(data, action(input, ...args));
// call update
update();
};
}
});
update();
}
const update = () => { const update = () => {
document.querySelector(mount).replaceChildren(view(data, actions)); document.querySelector(mount).replaceChildren(view(data, actions));
} }
// mount view // mount view
if (opts.view && mount) { if (opts.view && mount) {
update(); dispatch(data, actions);
} }
return { return {state}
state,
actions,
}
} }