-
-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Labels
needs reproA reproduction is neededA reproduction is needed
Description
I'd like to console.log each time an action is being called, with the passed params.
For example:
increment, 1
decrement, 2
setName, foo
etc.
This is my middleware:
const logger: TLoggerImpl = (config, logger) => (set, get, api) => {
const originalConfig = config(set, get, api);
const newActions = Object.fromEntries(
Object.entries(originalConfig).map(([actionName, actionFn]) => {
let enhancedFn = actionFn;
if (typeof actionFn === "function") {
enhancedFn = (...args: unknown[]) => {
const ret = actionFn(...args);
logger(actionName, args);
return ret;
};
}
return [actionName, enhancedFn];
}),
);
return { ...originalConfig, ...newActions };
};
It works when I wrap my store before zundo, but it's not ideal because I'm using debounce with handleSet.
I've seen a suggestion to use wrapTemporal here #184.
So I did:
wrapTemporal: (storeInitializer) =>
logger(storeInitializer, (fnName, fnArgs) => {
console.log(`${fnName} called with ${JSON.stringify(fnArgs)}`);
}),
But it only catches _handleSet with old state and new state.
Is there a way to do it?
Metadata
Metadata
Assignees
Labels
needs reproA reproduction is neededA reproduction is needed