0

I use this code to watch mutations, but the CB triggers only if old and new Values would NOT be equal,

VX.store.watch(
    getters => getters.focusedOn,
    ( value, oldValue ) => console.log( oldValue, value )
);

I get results like:

1 0

but I'm looking even for results like:

1 1

How can I get them? (even without using watch)

p.s. and I Don't like to convert my simple "focusedOn" to an object or so.

p.s. The createLogger reports all kind of mutations, so it made me thinking that there should be a way to get all of them.

Hatef
  • 1,168
  • 1
  • 7
  • 15
  • Does this answer your question? [How to watch prop even if it does not change?](https://stackoverflow.com/questions/65197803/how-to-watch-prop-even-if-it-does-not-change) – Boussadjra Brahim Jan 09 '21 at 21:03
  • thanks for suggestion, but I'm afraid Not (the link suggests to convert simple prop to an object or so). I am wondering why I can get the log of all mutations(via createLogger), but I can NOT get all mutations by watch? – Hatef Jan 09 '21 at 21:11
  • watch runs only when the old/new values are different – Boussadjra Brahim Jan 09 '21 at 21:15
  • Do u mean that providing old-new values in second watch parameters is useless when they are same? and there is no way to get all the possible mutation by watch?? so how can I get all mutations? like what createLogger does? – Hatef Jan 09 '21 at 21:18
  • A watch is for changes to state, caused by mutations. You're not asking about variable changes, rather the mutation events-- whether or not they change anything. A logger would just track the mutations at the time they're called. – Dan Jan 09 '21 at 21:33

0 Answers0