embiem / react-canvas-draw

React Component for drawing in canvas
https://embiem.github.io/react-canvas-draw/
MIT License
892 stars 315 forks source link

`onChange` behaviour is not as expected #117

Closed DipanshKhandelwal closed 2 years ago

DipanshKhandelwal commented 3 years ago

1. triggerOnChange is never called on clear

https://github.com/embiem/react-canvas-draw/blob/253b68ea73c01bd2c153b8a9dcb732e4a72b8432/src/index.js#L453-L468

2. triggerOnChange is called multiple times on calling undo: [ number of lines left on undo + 1]

triggerOnChange is called at the end of undo :

https://github.com/embiem/react-canvas-draw/blob/253b68ea73c01bd2c153b8a9dcb732e4a72b8432/src/index.js#L179-L184

But, simulateDrawingLines is also called on undo before triggerOnChange.

Now, simulateDrawingLines calls saveLine multiple times. Check line 276:

https://github.com/embiem/react-canvas-draw/blob/253b68ea73c01bd2c153b8a9dcb732e4a72b8432/src/index.js#L236-L279

And saveLine calls triggerOnChange at the end. Check line 446:

https://github.com/embiem/react-canvas-draw/blob/253b68ea73c01bd2c153b8a9dcb732e4a72b8432/src/index.js#L424-L447

embiem commented 2 years ago

thanks for the in-depth analysis. Seems to be related to #93, so I'll track this issue in there.