-
Notifications
You must be signed in to change notification settings - Fork 20
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
Rebuild / Bind #20
Comments
What's the status of this? I see there is an implementation for EDIT: I'm currently working on an implementation for @Bind, which supports both component-centric "global" binding as well as binding to single members of data-models within assignments, which expose themselves as "bind-functions" in that they accept a callback of signature |
Sorry for the answer delay ;) The code I'm using @:uiInitFunction(rebuild) @:uiNoComponent
class BaseComponent extends h2d.Object {
var bindList : Array<Void->Void> = [];
function registerCheckRebuild<T>( f : Void -> T ) : T {
var value = f();
registerBind(() -> {
var value2 = f();
var arr2 = Std.downcast((value2:Dynamic),Array);
if( arr2 != null ) {
var arr1 = Std.downcast((value:Dynamic),Array);
if( arr1 == null || arr1.length != arr2.length ) {
rebuild();
return;
}
for( i in 0...arr1.length )
if( arr1[i] != arr2[i] ) {
rebuild();
return;
}
} else {
if( value != value2 ) {
rebuild();
return;
}
}
});
return value;
}
function registerBind( f : Void -> Void ) {
bindList.push(f);
f();
}
override function sync(ctx) {
var cur = bindList;
for( f in cur ) {
f();
if( bindList != cur ) {
dom.applyStyle(ui.style, true);
break; // was rebuilt
}
}
super.sync(ctx);
}
public function rebuild() {
bindList = [];
removeChildren();
}
} The idea is that each app/framework can decide itself what it means by "data has been modified and needs rebuild", thus not requiring domkit to make strong assumptions on specific things. |
Thanks, finally I get a clearer picture of how this should work. I see a few issues with this for my use-case though:
Please have a look at my PR for Maybe something similar could be added for binding if-conditions & for-loops; along-side the current approach that is. |
|
Could be done like my
Yes, I understand that only
I have some lists where the dom.active property (and styling) gets lost if an entire list gets re-rendered if any element changes I saw that the UI in Northgard and Darksburg are looking fine ;-) But UI in my game is currently a flickering nightmare due to the lack of data-binding and minimalistic updates, because I have a lot going on in terms of realtime data |
I added @Bind support |
In order to allow for UI self-rebuild and automatic update within DomkitML declaration, we will introduce new metadata:
Gets translated to:
registerCheckRebuild can then be implemented on the framework base class to perform regular checks and rebuild the UI if data has changed, and registerBind for updating values regularly.
We also need something like:
That translates to:
So some vars can be updated before following rebuilds take place.
The text was updated successfully, but these errors were encountered: