|
@@ -1,3 +1,20 @@
|
|
|
+const createObservable = initial => {
|
|
|
+ return {
|
|
|
+ _get: () => initial, // TODO
|
|
|
+ _set: () => {}, // TODO
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const nameToHookName = name => "use" + name.chatAt(0).toUpperCase() + name.slice(1);
|
|
|
+
|
|
|
+const createHook = obs => {
|
|
|
+ // allow linters to pick this up as a hook
|
|
|
+ const useObservable = () => {
|
|
|
+ // TODO
|
|
|
+ }
|
|
|
+ return useObservable;
|
|
|
+}
|
|
|
+
|
|
|
export const createStore = (initial, actions = {}) => {
|
|
|
const store = {}; // maps keys to observables
|
|
|
const hooks = {};
|
|
@@ -8,7 +25,9 @@ export const createStore = (initial, actions = {}) => {
|
|
|
if (obs) {
|
|
|
obs._set(newValue);
|
|
|
} else {
|
|
|
- // TODO
|
|
|
+ const newObs = createObservable(newValue);
|
|
|
+ store[key] = newObs;
|
|
|
+ hooks[nameToHookName(key)] = createHook(newObs);
|
|
|
}
|
|
|
});
|
|
|
};
|