aui: ADataBinding bad design
At the moment, ADataBinding envolves a lot of boilerplate instead of reducing it.
Example usecases
Increase integer field by 1
Expected:
mViewModel.integerField += 1;
Actual:
mViewModel.setValue(&ViewModel::integerField, mViewModel->integerField + 1);
Direct and indirect field binding:
Direct binding is almost acceptable:
_new<ALabel>() && mViewModel(&ViewModel::stringField),
But what about label and integer binding?
_new<ALabel>() let {
mViewModel.addObserver(&ViewModel::integerField, [=](int v) {
it->setText("The value is: {}"_format(v));
});
},
Boss music: lists
I.e. I want to make a basic todo app:
struct ViewModel {
struct Item {
AString title;
bool done = false;
};
AVector<Item> items;
};
I have no idea how to do this.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 29 (6 by maintainers)
Very nice approaches here, I’m already seeing in which use cases they will be helpful to me! The third design seems to be closer of what we have in C#, but the trailing parenthesis make it somehow unconventional. I could have tried something too if I was familiar to this level of metaprogramming. But at this stage I think it’s on a very good path, theses can even be wrapped in macros, like
AUI_ACCESSOR_PROPERTY(name, &CustomSetter::setName, &CustomSetter::getName)for custom get/set andAUI_MEMBER_PROEPRTY(AString, name)for default get/set.Anyway, I’m eager to see where those things are going!
The third design
I’m trying to address here
{this}issue of the second design. As the second design, this one is intended for referencing external setter/getter/signal. I’m injecting pointer to this by method: