mirror of https://github.com/n2geoff/um
setup action signature (state, event)
This commit is contained in:
parent
c996aac35a
commit
21f4c4344d
24
src/app.js
24
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}
|
||||
}
|
Loading…
Reference in New Issue