From 21f4c4344dfdd8f870f3182de10e821f93cf34e3 Mon Sep 17 00:00:00 2001 From: Geoff Doty Date: Sun, 5 May 2024 15:04:45 -0400 Subject: [PATCH] setup action signature (state, event) --- src/app.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/app.js b/src/app.js index eeac42b..b267654 100644 --- a/src/app.js +++ b/src/app.js @@ -23,17 +23,31 @@ export default function app(opts) { 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 = () => { document.querySelector(mount).replaceChildren(view(data, actions)); } // mount view if (opts.view && mount) { - update(); + dispatch(data, actions); } - return { - state, - actions, - } + return {state} } \ No newline at end of file