-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
REF-1052/rx.State as Base State #2146
Conversation
c93db07
to
60cc30f
Compare
023d40a
to
02ba981
Compare
f7e57b9
to
ca82705
Compare
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Masen Furer <m_github@0x26.net>
Only track direct subclasses of each BaseState class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few more small things
if len(state_subclasses) > 1: | ||
raise ValueError( | ||
"rx.State has been subclassed multiple times. Only one subclass is allowed" | ||
"rx.BaseState cannot be subclassed multiple times. use rx.State instead" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"rx.BaseState cannot be subclassed multiple times. use rx.State instead" | |
"rx.BaseState cannot be subclassed multiple times. Use rx.State instead." |
# reset rx.State subclasses | ||
State.class_subclasses.clear() | ||
# self.app_module.app. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# reset rx.State subclasses | |
State.class_subclasses.clear() | |
# self.app_module.app. | |
# Reset rx.State subclasses. | |
State.class_subclasses.clear() |
config = get_config() | ||
module = ".".join([config.app_name, config.app_name]) | ||
sys.path.insert(0, os.getcwd()) | ||
app = __import__(module, fromlist=(constants.CompileVars.APP,)) | ||
if reload: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When running AppHarness or unit tests via pytest, delete duplicate state names (and basically redefine the state tree with the new class). In a previous patch i removed this bit of code (https://github.com/reflex-dev/reflex/pull/2227/files#diff-704efe440192781e072231490ac1d12defd1aba5f6debafbc7907eebcc2abcc7L304-L314). But it turns out to be necessary. So I restructured the duplicate name check a bit to indicate that this subclass resetting should only occur in testing modes, and expand a bit on why we're doing it that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
This PR renames
rx.State
torx.BaseState
and creates a base state(rx.State
) for all client apps. With this approach every substate will be a child(or substate) ofrx.State
. Also allows multiple inheritance fromrx.State
:docs: reflex-dev/reflex-web#306