updux/src/buildActions/index.ts

21 lines
604 B
TypeScript
Raw Normal View History

2021-10-07 16:04:15 +00:00
export function buildActions(actions = {}, subduxes = {}) {
2021-09-28 22:13:22 +00:00
// priority => generics => generic subs => craft subs => creators
const merged = { ...actions };
Object.values(subduxes).forEach(({ actions }) => {
2021-10-07 16:04:15 +00:00
if (!actions) return;
2021-09-28 22:13:22 +00:00
Object.entries(actions).forEach(([type, func]) => {
if (merged[type]) {
if (merged[type] === func) return;
throw new Error(
`trying to merge two different actions ${type}`
);
}
merged[type] = func;
});
});
return merged;
}