Skip to content
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

Handle Cascading Bindings #28

Open
lemirep opened this issue Mar 31, 2022 · 0 comments
Open

Handle Cascading Bindings #28

lemirep opened this issue Mar 31, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@lemirep
Copy link
Contributor

lemirep commented Mar 31, 2022

Often, I have to deal with a Property<T*> p where T itself contains properties. Given the property p is using a pointer type, I cannot binding directly to p->someProperty given p might be null. Therefore I would need to have a way to create a binding to a function that can itself return binding to another property or a value depending on whether p() is null.

// GIVEN
struct TypeA {
Property<float> value { 1.0f };
};

struct TypeB {
Property<TypeA *> a { nullptr };
};

// WHEN
TypeB myB;

// In a perfect world I would do Property<float> v = makeBinding(myB.a->value);
// Except I can't if myB.a is null

// THEN
CHECk(myB.a() == nullptr);

// WHEN
Property<float> v = makeBinding([] (TypeA *a) { 
                                    if (a)
                                       return makeBinding(a->value);
                                    return 0.0f; // or a binding to a default property
                                }, myB.a);

// THEN -> Returns default value
CHECK(v() == 0.0f);

// WHEN
TypeA myA;
myB.a = &myA;

// THEN -> Return bound value
CHECK(v() == 1.0f);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants