When listening for events in Web3 the listener can sometimes emit a 'changed' event. In the docs in the example code there is a comment explaining that the event should be removed from local database.
When observing console.log of 'data' and 'changed' events i sometimes see that a event is emitted as 'data' then 'changed' and then as 'data' again.
I want to implement caching the information properly in my local db but I do not understand why such a situation occurs. Additionally can I be sure that the order in which the 'data' and 'changed' events occur will result in properly cached data (can i be sure that data regarding the same event wont be sent as 'data' => 'data' => 'changed' which would result in me saving the event twice and then deleting the event from local database).
https://web3js.readthedocs.io/en/v1.4.0/web3-eth-contract.html#id50
myContract.events.MyEvent({
fromBlock: 0
})
.on('changed', function(event){
// remove event from local database
})