kdab / kdbindings Goto Github PK
View Code? Open in Web Editor NEWReactive programming & data binding in C++
Reactive programming & data binding in C++
Use Thread 1 with normal signal evaluation to mark a binding as dirty.
Then have all the dependent properties associated with a BindingEvaluator.
This binding evaluator would then be evaluated by Thread 2 (typically GUI Thread), so the evaluation actually happens on a separate thread.
For this to work the following would need to be thread-safe:
It would be nice to be able to do:
#include <KDBindings/signal.h>
on systems with case-sensitive filesystems so that it matches the other KD libraries that we have.
Hi,
As a developer it would be nice to be able to connect the signals to Javascript functions in Qt.
Even if clazy generates warnings in CI the runner isn't considered to have failed.
How do we fix this?
When T is an aggregate type, eg struct Rect { int x; int y; int width; int height; }
It would be great to be able to access members of Property, i.e that:
Property<Rect> r;
auto widthProp = makeBoundProperty(r.width);
This slightly overlaps with what @lemirep is asking about in #28, except in my case the aggregate does not contain Property<>
members. The desired behaviour can be done using a function argument to makeBoundProperty
: the question is whether some overload of operator-dot (and ->
, presumably) could synthesise the access.
Forgetting to disconnect a connection can lead to serious issues.
So we should allow users to at least get a warning in that case.
However, we likely want to put this behind a flag of some sort to not break existing code.
Having the ability to control when a connection is emitted could be advantageous, especially in a multi-threaded context, where a worker thread might emit a signal, but the slot should be called in an event loop on a GUI thread.
To control when exactly a connection is evaluated, implement a ConnectionEvaluator, similar to the BindingEvaluator, that can control when exactly a slot is called.
Add a function connectDeferred
(or similar) that takes a ConnectionEvaluator as the first argument, then takes the same arguments as the normal connect function.
This slot would then queue the actual function to be called in the ConnectionEvaluator. The queued functions in the ConnectionEvaluator could then be called at any time, similar to how evaluateAll works on the BindingEvaluator.
The difference here would be that connections might actually be emitted multiple times between calls to the evaluator, so these calls would then also need to be emitted multiple times.
A single shot connection could possibly be implemented by creating a binding that captures its own ConnectionHandle and disconnects it when the signal is emitted.
Open question: How to capture the ConnectionHandle in the slot itself?
The move constructor of Property is marked noexcept
, but - as long as it emmits public moved
signal - it can throw from any slot. Simple example:
TEST_CASE("Nothrow move")
{
try {
std::set_terminate([] {
std::cerr << "TERMINATED" << std::endl;
});
Property<int> p;
p.moved().connect([&] { throw 0; });
Property<int> p2 = std::move(p);
} catch (int) {
}
}
The program will call std::terminate
as it throws from noexcept
function.
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);
At the moment I cannot use a const Property in a binding.
const Property<float> someValue = makeBinding(someExpression);
Property<float> boundValue = makeBinding(someValue); // This does not compile
A const Property means it cannot be assigned to again but its value still might change (if the value of the const property is a binding). Therefore, being able to use a const Property in a binding would make sense.
It may be unexpected for users that a signal emission doesn't reach its slot when an emission is still queued up on disconnect.
Therefore, document that this is happening by adding some kind of logging.
Assuming #41 is merged with this behavior.
As is commonly used in the js world or for e.g. https://github.com/KDAB/KDToolBox/tree/master/qt/KDSignalThrottler
Not sure which type of syntax would be most useful.
Maybe:
mySignal.debounce(100).connect(&MyClass::doSomething, myObj);
?
Can we achieve following in KDBindings?
Basically wanted to check if KDBindings support multithreaded property binding evaluation?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.