mercredi 7 juin 2023

Is there a design pattern for logic performed on multiple event listeners

I have logic that is performed on steps on multiple different events. for example some logic is done on mousedown which changes some shared state that mousemove uses which also changes some shared state that finally mouseup uses. for example it might look something like this

function handleMouseDown(){
...
setState1()
...
setState2()
}
function handleMouseMove(){
...
consumeState2
...
consumeState1
setState3()
...
}

function handleMouseUp(){
...
consumeState3
...
}

The problem is that I feel that dependancy between the logic performed in those 3 events is implicit, which is in my opinion makes it hard to figure out what the code does especially if you considered that I have more than one task performed the same way. So my question is there a design pattern for this?

Aucun commentaire:

Enregistrer un commentaire