|
@@ -2,7 +2,15 @@ import { useState, useEffect } from "react";
|
|
|
|
|
|
const shallowEq = (x, y) => x === y;
|
|
|
|
|
|
-export const createStore = (initial, actions = {}) => {
|
|
|
+export const consoleMonitor = (key, original) => {
|
|
|
+ let val = original;
|
|
|
+ console.log(`Initializing ${key} with ${JSON.stringify(original)}`);
|
|
|
+ return newVal => {
|
|
|
+ console.log(`Updating ${key} from ${JSON.stringify(val)} to ${JSON.stringify(newVal)}`);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export const createStore = (initial, actions = {}, monitor = null) => {
|
|
|
const get = {};
|
|
|
const update = {};
|
|
|
const hooks = {};
|
|
@@ -13,7 +21,7 @@ export const createStore = (initial, actions = {}) => {
|
|
|
setter(value);
|
|
|
} else {
|
|
|
let _val = value;
|
|
|
- let _listeners = [];
|
|
|
+ let _listeners = monitor === null ? [] : [{ callback: monitor(key, value), equality: shallowEq }];
|
|
|
|
|
|
get[key] = () => _val;
|
|
|
|