Titanium JIRA Archive
Alloy (ALOY)

[ALOY-563] Allow for autoinitialization of Alloy repetition views from global collections on creation

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionFixed
Resolution Date2013-03-30T14:10:46.000+0000
Affected Version/sn/a
Fix Version/sAlloy 1.0.0, 2013 Sprint 04
Componentsn/a
Labelsalloy, alloy-generate
ReporterDavide Cassenti
AssigneeUnknown
Created2013-03-12T11:38:40.000+0000
Updated2018-03-07T22:25:46.000+0000

Description

A repetition view that is bound to a global collection is not initialized to the contents of the collection upon creation. Consider the following snippet:
<ScrollView id="documentsContainer" layout="vertical" dataCollection="document" dataFilter="filterDocuments" onSingletap="documentRowClicked">
    <Require src="indexdocumentrow" notClickable="0"/>
</ScrollView>
The autogenerated initialization code for this piece looks like this:
var __alloyId31 = function(e) {
        var models = filterDocuments(Alloy.Collections.document), children = $.__views.documentsContainer.children;
        for (var d = children.length - 1; d >= 0; d--) $.__views.documentsContainer.remove(children[d]);
        len = models.length;
        for (var i = 0; i < len; i++) {
            var __alloyId28 = models[i];
            __alloyId28.__transform = {};
            var __alloyId30 = Alloy.createController("indexdocumentrow", {
                notClickable: "0",
                id: "__alloyId29",
                $model: __alloyId28
            });
            __alloyId30.setParent($.__views.documentsContainer);
        }
    };
    Alloy.Collections.document.on("fetch destroy change add remove reset", __alloyId31);
To have this repeater view initialize, I need to either fetch the collection (which is already done at the beginning of the app) or fire one of the events from the last line, which is more suitable and which is what I do:
Alloy.Collections.document.trigger("change");
The problem now is, when I fire this event, all listeners in all open windows get this event. This means that all views in every window are first getting removed and then initialized again. This leads to enormous lagging. As for me, there must be a markup attribute or another means to initialize the collection right upon creation, this would make it logical. See original discussion: https://developer.appcelerator.com/question/149192/initialization-of-a-repeater-view-with-databinding

Comments

  1. Andrey Chirikba 2013-03-29

    I would suggest at least making the initialization function (currently an autogenerated name) accessible to user-written code. This would mean we can call it upon controller initialization without resorting to faking events. This would also help the user to reinitialize the view on events other than the default ones.
  2. Tony Lukasavage 2013-03-30

    Not exactly a duplicate, but this is actually resolved by ALOY-489. You can use the new dataFunction attribute to give an explicit name to the binding function.

    index.xml

       <Alloy>
           <Window>
               <TableView dataCollection="someCollection" dataFunction="doBinding"/>
           </Window>
       </Alloy>
       

    index.js

       // fire binding manually
       doBinding();
       

JSON Source