-
|
Hello every, I have a question about var and its value. class State(pc.State):
"""The app state."""
test = [1,2,3]The variable become BaseVar(name='test'.....) in app.init_subclasee cls.base_vars = {
f.name: BaseVar(name=f.name, type_=f.outer_type_).set_state(cls)
for f in cls.get_fields().values()
if f.name not in cls.get_skip_vars()
}
cls.computed_vars = {
v.name: v.set_state(cls)
for v in cls.__dict__.values()
if isinstance(v, ComputedVar)
}
cls.vars = {
**cls.inherited_vars,
**cls.base_vars,
**cls.computed_vars,
}
cls.event_handlers = {}
print(cls.vars) # My addBut when we use the compiler, it need real value([1,2,3]). If anyone can help me, I will be grateful. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
@TaiJuWu the State attribute is a The value contains the actual list when it is accessed from the instance, i.e. from an event handler. This is called when some client interaction triggers an event on the state. Within the event handler, accessing In the context where you have a reference to the |
Beta Was this translation helpful? Give feedback.
@TaiJuWu the State attribute is a
BaseVarwhen it is accessed from the class, i.e.State.test. This is used when creating the frontend: the actual value is in the state dict on the client side and will be filled in by the BaseVar at runtime.The value contains the actual list when it is accessed from the instance, i.e. from an event handler. This is called when some client interaction triggers an event on the state. Within the event handler, accessing
self.testwill get the reallistvalue, not theBaseVar.In the context where you have a reference to the
Stateclass, during compile time, it doesn't make any sense to access the actual value, because the page is compiled for all clients, b…