Giter Site home page Giter Site logo

Rebuild / Bind about domkit HOT 6 CLOSED

heapsio avatar heapsio commented on July 17, 2024
Rebuild / Bind

from domkit.

Comments (6)

rcstuber avatar rcstuber commented on July 17, 2024

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.

ncannasse avatar ncannasse commented on July 17, 2024

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.

rcstuber avatar rcstuber commented on July 17, 2024

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.

ncannasse avatar ncannasse commented on July 17, 2024
  • 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 an if or for 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.

rcstuber avatar rcstuber commented on July 17, 2024
  • 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 an if or for 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.

ncannasse avatar ncannasse commented on July 17, 2024

I added @Bind support

from domkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.