Clean up C++ repeated component creation

Centralize the self_weak setup to be emitted only once, in the create()
function. create() is now always emitted and equipped with a parent
parameter, for non-root components. This allows slightly simplifying the
generic repeater code.
This commit is contained in:
Simon Hausmann 2020-11-19 16:41:26 +01:00
parent 52aae34f94
commit 9c9e6c7563
2 changed files with 9 additions and 10 deletions

View file

@ -505,7 +505,7 @@ class Repeater
struct ComponentWithState
{
State state = State::Dirty;
std::optional<vtable::VRc<private_api::ComponentVTable, C>> ptr;
std::optional<ComponentHandle<C>> ptr;
};
std::vector<ComponentWithState> data;
bool is_dirty = true;
@ -560,9 +560,7 @@ public:
for (int i = 0; i < count; ++i) {
auto &c = inner->data[i];
if (!c.ptr) {
c.ptr = { vtable::VRc<private_api::ComponentVTable, C>::make(parent) };
const_cast<C *>(&**c.ptr)->self_weak =
vtable::VWeak<private_api::ComponentVTable, C>(*c.ptr);
c.ptr = C::create(parent);
}
if (c.state == RepeaterInner::State::Dirty) {
(*c.ptr)->update_data(i, m->row_data(i));