|
@@ -36,6 +36,8 @@ const createHook = obs => {
|
|
|
return useObservable;
|
|
|
}
|
|
|
|
|
|
+const mapValues = (src, fn) => Object.fromEntries(Object.entries(src).map(([key, val]) => [key, fn(val)]));
|
|
|
+
|
|
|
export const createStore = (initial, actions = {}) => {
|
|
|
const store = {}; // maps keys to observables
|
|
|
const hooks = {};
|
|
@@ -55,9 +57,9 @@ export const createStore = (initial, actions = {}) => {
|
|
|
|
|
|
mergeState(initial);
|
|
|
|
|
|
- const dispatch = Object.fromEntries(Object.entries(actions).map(([name, action]) => [name, (...args) => mergeState(action(...args))]));
|
|
|
+ const dispatch = mapValues(actions, act => (...args) => mergeState(act(...args)));
|
|
|
|
|
|
- const selector = Object.fromEntries(Object.entries(store).map(([key, obs]) => [key, obs._get]));
|
|
|
+ const selector = mapValues(store, obs => obs._get);
|
|
|
|
|
|
return [hooks, dispatch, selector];
|
|
|
}
|