-
-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor views and add ComponentResponse class to help handle requests #672
Conversation
This is a work in progress, and will certainly need feedback & discussion if it's ever to be accepted. I realize changes this large have a chance of being rejected, so I decided to open the PR while it's still in a draft state. @adamghill I'll continue to work on the refactor for now, but let me know if this heads in a direction you don't approve of 😄 |
looks like black is adding changes where I haven't edited anything. Is this not the black version you normally use? Line 149 in 07babfb
|
I really appreciate you digging into this! This code is... extremely gnarly. It got built up over lots of time. Looking forward to seeing how this progresses. I have decent test coverage last I checked (something like 90%?) however, this will need extensive manual testing as well because of where it lives. I've slowly been moving from |
Awesome! I'm glad you're open to it so I'll keep working away 🥳. I think it's going to take me the weekend to get this MR to a state where I'm ready for you to give a peek / feedback. I'll ping you when I hit that stage
Haha yeah, I haven't touched the test suite yet, but have been doing manual checks along the way. If it get's too repetitive, I might write a test using the
Ah, gotcha. I haven't used ruff before but I'll switch over to that |
Have you looked at playwright at all? I did a proof of concept at some point for |
I haven't! I'll check that one out too |
I'm going to pause work on this PR for a couple days. It is still a work in progress and not ready for any manual or automated testing because I need to finish up some subclass definitions (such a But I would say this PR is ready for feedback at the concept level:
To help with skimming through:
|
just to add -- sorry this is such a massive PR. I know that can cause headache as a maintainer 😅. So I wouldn't spend any more than 10 min looking through for now. I'll let you know when its actually ready for a full code review though |
manually checking different types of unicorn setups and actions:
|
This MR is ready for a review -- but not merge. Remaining to-do items before merging:
@adamghill no rush on this 😄 . I can only help out on the weekends atm, so I might not get to your feedback right away anyways |
as a side -- do you squash commits on merge? I'm pretty loose with how often I commit and with what the commit messages are |
I usually do! Although probably easiest if you rebase when you get to a good place and force push to your branch. Then I can just do a clean merge. |
I'm going to revisit this PR if that's okay. There are a lot of issues being opened about child components that I'd like to help with, but the current state of the source code makes debugging pretty difficult -- in fact, I could only track down the issue for #666 within this PR, rather than on the main branch |
That would be great! I look forward to seeing how if this code could be easier to grok. :) |
I kinda went overboard on the refactor. There are the many changes that I summarized above, and then in the 2 most recent commits:
|
I think there are too many changes (and several feature regressions) where it's not reasonable to ask for an MR review + eventual merge. However, this can still serve as an outline/model for future refactors in the package. Because of my own deadlines (🤢), I need this fork and a couple of its fixes in my prod env -- so I'm likely going to "hard fork" from here and use this code within my own packages, where I'll gradually continue to work on it. Hopefully over time, some of its refactor choices make it in this repo though! I'm going to close this MR, just to indicate it's not planned for any review or merging |
Summary
The end goal is to make code easier to read/follow for new devs, without changing anything about how users create apps. Changes include:
views/.__init__.py
intoviews/message.py
. Somessage
fxn is now a class:UnicornMessageHandler
ComponentResponse
class to help distinguish fromComponentRequest
ComponentRequest
to simplify higher-level use in request handlingAction
to be an abstract base class, rather than a generic. And added subclasses for each action type (CallMethod
,Reset
,Refresh
,Toggle
,SyncInput
, etc.)Motivation
I was trying to help find a fix for several issues (#650 #662 #666), but was struggling to follow along with some of the code. It is heavily focused on large functions and modifying objects in-place, rather than more well defined classes + methods. I'm sure others have ran into this issue before, so I started a refactor in hopes to make the code cleaner & easier to follow.
Details of changes
Articulating changes in a refactor like this is difficult, but here's my stab at describing what I changed & why:
ComponentRequest
is not treated as immutiable, and it is gradually converted to a "ComponentResponse" within various methods. I decoupled these steps so that's it's easier to follow, and I also added aComponentResponse
base class to help some morecall_method.handle
overcomplicates a lot of data passing -- especially in how it generates data in _process_component_request and generatesReturn
objects. Lots of this can be simplified by further developing theAction
andComponentResponse
classes, so I added several methods/properties to these classes to help.UnicornView
is modified in various locations, but it's much easier to follow when there are reusable methods on the class directly. I "pushed down" some code fromviews.__init__.py
into theUnicornView
to make higher-level functions easier to follow + create more reuseableUnicornView
methods.