#console.log every action and guard call
1 messages · Page 1 of 1 (latest)
Do you just want to log the state whenever the state machine transitions?
You can do this:
const actor = interpret(machine);
actor.subscribe(state => {
console.log(state);
});
actor.start();
No, I want to log every action/guard call. I have many actions or guards and I put a console.log in them so I can see what the context or event is while its being called. Its great for debugging, because when there are multiple actions call on entry/exit/transition I can see what state in each action is. And I wonder if its possible to avoid adding .log in each function declaration separately. I hope it make sense. I can create a sandbox for it, if its still confusing
It makes sense. There's no abstraction for this directly in XState currently
I also have a problem where console.log() gets ignored entirely when added inside a guard function
That shouldn't happen. Can you post a repro?
Not able to do that..
The machine is created like this
return createMachine(
getConfig<T, TData>(arg1, arg2, arg3, data),
getOptions<T, TData>(services, arg2, arg3, data)
);
Right but the console should not be ignored when evaluating guards
Hmm, if I do the guard inline the conosle.log works
target: ...
cond: (context, event) => {
console.log(...);
}
The guard function wasn't really a pure function but even after I've made it pure it still didn't do the console.log