MVCoconut / coconut.ui

Wow, such reactive view! Much awesome!
The Unlicense
89 stars 9 forks source link

exception after removing items from ObservableArray #48

Closed Antriel closed 3 years ago

Antriel commented 4 years ago

Running mostly github versions of everything, I get Cannot read property '__coco_i' of undefined in RowView.render.

class Main {
    public static function main() {
        var data = new Data();
        coconut.ui.Renderer.mount(
            cast js.Browser.document.body.appendChild(js.Browser.document.createDivElement()),
            coconut.Ui.hxx('
                <div><for {item in data.rows}>
                    <RowView row={item} />
                </for></div>')
        );
        haxe.Timer.delay(function() data.rows.splice(1, 1), 1000);
    }
}

class RowView extends coconut.ui.View {
    @:attribute var row:Row;
    function render() '<div>{row.i}</div>';
}

class Data implements coconut.data.Model {
    var rows:tink.state.ObservableArray<Row> = new tink.state.ObservableArray(
        [for(i in 0...10) new Row({ i: i })]
    );
}

class Row implements coconut.data.Model {
    @:editable var i:Int;
}
grepsuzette commented 4 years ago

Issue reproduced here.

back2dos commented 4 years ago

Well, this one is not so easy to explain ... basically, the ObservableArray's API has a few design flaws concerning iterators, but using <for {item in data.rows.values}> sidesteps this issues.

Antriel commented 4 years ago

data.rows.values() works. Thanks.

back2dos commented 3 years ago

Fixed in tink_state