-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
RefreshingItem #38
Comments
Maybe there's a way to do it without the need to know the form in advance Pseudo code: # Some Form class
from anvil_extras import FormItemListener
class ItemTemplate(ItemTemplateTemplate):
def __init__(self, **properties):
FormItemListener.init(self) # FormItemListener
_classes = set()
def _item_override(cls):
base_item = super(cls, cls).item
def item_getter(self):
return base_item.__get__(self, cls)
def item_setter(self, item):
item = _cls_for_refreshing_item(item)
item._form = self
base_item.__set__(self, item)
return property(item_getter, item_setter)
def init(form):
cls = type(form)
if cls in _classes:
return
else:
cls.item = _item_override(cls)
_classes.add(cls)
_dict_setitem = dict.__setitem__ # save an attribute lookup on each call to __setitem__
class _D(dict):
def __setitem__(self, key, value):
_dict_setitem(self, key, value)
form = getattr(self, '_form', None)
if form is not None:
form.refresh_data_bindings()
_cls_for_refreshing_item = _D proof of concept: |
In the proof of concept i've suggest 3 possible apis # Some Form class
from anvil_extras import FormItemListener
class ItemTemplate(ItemTemplateTemplate):
def __init__(self, **properties):
FormItemListener.init(self) # Some Form class
from anvil_extras import FormItemListener
class ItemTemplate(FormItemListener.BaseClass, ItemTemplateTemplate): # Some Form class
from anvil_extras import FormItemListener
class ItemTemplate(ItemTemplateTemplate):
...
FormItemListener.init_class(ItemTemplate) # or equivalent decorator I think option 1 or 3 are best... |
Excellent! I went to bed last night thinking there must be a way to do this with a decorator on the Form class and I wake up to find the code for that has magically appeared! |
I'm happy to pick this up from here (but also happy for you to carry on if you prefer). |
go for it. |
A client side class for use as a form's item attribute.
It exposes a dict like interface but calls the form's refresh_data_bindings method whenever it's updated.
It will need to take a form instance as one of its init arguments.
It could provide an option to behave like a defaultdict.
Prompted by https://anvil.works/forum/t/data-binding-not-refreshing/7923/4
The text was updated successfully, but these errors were encountered: