chrvadala / react-svg-pan-zoom

:eyes: A React component that adds pan and zoom features to SVG
https://chrvadala.github.io/react-svg-pan-zoom/
MIT License
681 stars 127 forks source link

Hookify all components (WIP) #152

Closed TimVanMourik closed 3 years ago

TimVanMourik commented 4 years ago

This is an attempt to rewrite all classes with React hooks.

While rewriting, I got in trouble with the value variable. It's basically containing the entire state of the component, but is managed outside of the React state management. The current rewrite tries to unify this.

The current status of the rewrite is

This is still Work In Progress, do not merge yet.

chrvadala commented 4 years ago

This is a great feature and probably will require a new major release 👍 Thanks for your work. Feel free to ask me help 😎

TimVanMourik commented 4 years ago

Hi @chrvadala (and other potentially interested folks), just a check-in update:

I would very much welcome a look on this and would love to hear your opinion on the changes. As you mentioned before, this most certainly requires a new major release once it's all done.

chrvadala commented 4 years ago

Thanks for your huge work. You changed a lot of files, so a review might require time. I'll provide you a feedback as soon as possible.

chrvadala commented 4 years ago

Hi @TimVanMourik , I had the opportunity to review your changes, so here my comments:

Finally, I'd like to provide a new library version based on React Hooks, but I need to keep any available features in order to avoid breaking changes. I think that we can work together to reach this goal. On a different branch I started to write some unit tests, because I'd like to release a new major versione with higher code coverage. Please feel free to contact me if you have any question

TimVanMourik commented 4 years ago

Hi @chrvadala, Thanks for your time to look into the PR.  I realise I made a massive update without first discussing serious API changes. Communication for open source projects can be a bit slow, so I decided just to go ahead and see what you'd think of the result. So thanks again for the feedback!

Ok, this sounds like I'm a huge redux fan. Which is partially correct, but in this case I just genuinely think it might resolve many problems. I'm going to try and prepare some proof of principle and maybe I can convince you it's a good idea :) If not, no worries, then I'm sure it was a good exercise for me.

chrvadala commented 4 years ago

Hei man, you did a lot of work here https://github.com/chrvadala/react-svg-pan-zoom/pull/162. I appreciate it but, as suggested in my previous comment, you don't need to refactor all these stuffs to obtain a hooked version of the viewer. I agree that reducers are a great thing. I built on top of Redux this other library https://github.com/cvdlab/react-planner, so I know very well this library, but tough I like this pattern I think that is better to keep this library as much as decoupled from other libraries.

Man, I'd like to give you the right way in order to avoid you to make something that I can't merge. I did a brief analyse of what works is needed in order to obtain a hooked version of this library. Hope that this list might help you:

From my side I'm working in order to make stronger the rest, adding some unit tests. I'm pushing my code on this PR https://github.com/chrvadala/react-svg-pan-zoom/pull/164 .

Feel free to ask me for any question. Thanks again for your contribution.