ianharrigan / haxeui

IMPORTANT NOTE! This repository is no longer maintained. Please consider the newer version: https://github.com/haxeui/haxeui-core
http://haxeui.org/
392 stars 47 forks source link

Review listview/datasources #255

Open ianharrigan opened 9 years ago

ianharrigan commented 9 years ago

This seems to be a bottle neck and could do with a new implementation.

Telemetry would be needed first, via either hxScout or GameConsole

Mechameesh commented 9 years ago

Just wanted to chime in on this;

I'm mostly using listviews / datasources with dynamic items being changed, added and removed all the time. For convience i'm using a set of functions for these tasks:

inline function setDataSourcePosition(source:IDataSource, index:Int) {
    if (index >= source.size())
        return;

    var iterator:Int = 0;                   
    source.moveFirst();
    while (iterator < index) {          
        source.moveNext();
        iterator++;
    } 
}

inline function removeDataSourceItemAt(source:IDataSource, index:Int) {
    setDataSourcePosition(source, index);               
    source.remove();
}

inline function getDataItemAt(source:IDataSource, index:Int):Dynamic {
    setDataSourcePosition(source, index);
    return source.get();
}

But as you can see, this leads to a lot of needless iteration over the datasource. If I don't use the convience functions, I have to write out the iteration snippet for every time I want to manipulate the datasource. It might be an idea to check out the apache flex implementation of datasources / collections / bindable data :

https://git-wip-us.apache.org/repos/asf?p=flex-sdk.git;a=tree;f=frameworks/projects/framework/src/mx/collections;h=621cd28f49d6ef5be839655093ddf3ad46cd6b73;hb=HEAD

with some documentation:

https://flex.apache.org/asdoc/mx/collections/ListCollectionView.html

ianharrigan commented 9 years ago

Totally agree, i was actually thinking about doing away with them entirely for version 2, ie the basic listview would just use an array, if you wanted lazy loading that would be an extension of some description LazyListView or whatever.

Thanks for the links though, i might go through them all properly first before i make a decision to drop them

Mechameesh commented 9 years ago

I think the main reason to maintain a proper interface to a datasource would be to implement one-way / two-way binding to variables. I haven't given this too much though, but perhaps a IBindable interface for classes that can be bound? Would save a lot of boilerplate code for itemrenderers