Comments (6)
What's the status of this? I see there is an implementation for @rebuild
, but @bind
logic is still missing. Any suggestions how to handle data-binding with DomKit?
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 Void->Void
– for triggering a rebuild – and return the members current value immediately. I'm evaluating possible edge cases before opening a PR for discussion
from domkit.
Sorry for the answer delay ;)
You're correct that @rebuild
is correctly implemented and @bind
is not.
The code I'm using @rebuild
is the following:
@: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.
from domkit.
Thanks, finally I get a clearer picture of how this should work. I see a few issues with this for my use-case though:
- Requires polling for changes, potentially checking a lot of unnecessary expressions before finding a change
- Rebuilds the entire component, even if only parts of it require changes
- Re-renders entire lists if items get added/removed, potentially causing flickering or lag
Please have a look at my PR for @bind
logic (#31). It allows for expressions to only re-evaluate if a variable's value within it has changed, being more of an event-driven solution. I made it so that it also makes no assumptions of how the actual binding looks like and thus is very data-layer agnostic.
Maybe something similar could be added for binding if-conditions & for-loops; along-side the current approach that is.
from domkit.
- Polling : sure, but I'm not sure how we can do that without polling
- Entire rebuild : please note that it's only the case for
@rebuild
, and this should only be used when you have anif
orfor
loop in domkit that changes its content - there should not be any flickering, and we do use rebuilds in our games without perceptive lag
from domkit.
- Polling : sure, but I'm not sure how we can do that without polling
Could be done like my @bind
implementation, where if parts of an expression change the entire expression is re-evaluated (event-driven)
- Entire rebuild : please note that it's only the case for
@rebuild
, and this should only be used when you have anif
orfor
loop in domkit that changes its content
Yes, I understand that only @rebuild
annotated expressions are affected, but a component may have several of those and the entire component gets rebuild if any of those change, because there is no reference as to which sub-tree the expression refers to
- there should not be any flickering, and we do use rebuilds in our games without perceptive lag
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
from domkit.
I added @Bind support
from domkit.
Related Issues (20)
- [Regression] Text node issue HOT 4
- Failed to load module
- Issue with for iterator
- @:uiComp metadata behavior HOT 7
- @:uiInitFunction only works for child classes
- HL bytecode hot reload and DomKit HOT 2
- Domkit License unclear HOT 3
- Adding Bitmap to domkit component, bitmap.dom is null HOT 2
- Transitions HOT 1
- Missing super component registration flow HOT 2
- Array alloc in applyStyle HOT 3
- Multiple CSS files, how to handle HOT 1
- :odd and :even not being refreshed HOT 3
- Uncaught TypeError (JavaScript target) HOT 1
- d9ef202 breaks compilation with the latest released version of haxe HOT 3
- Default component type resolution HOT 4
- Domkit sample in Heaps + example in docs doesn't compile HOT 4
- domkit css parsing support broken in javascript HOT 3
- A simple component causes: "domkit.Identifier should be String" HOT 1
- Incorrect CSS Id selector for component arrays
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from domkit.