Titanium JIRA Archive
Alloy (ALOY)

[ALOY-1000] Model Binding a View generates multiple calls to update the data of bound objects.

GitHub Issuen/a
Resolution Date2014-05-28T16:06:53.000+0000
Affected Version/sn/a
Fix Version/sAlloy 1.5.0
ReporterBert Grantges
AssigneeFeon Sua Xin Miao


I have a simple view that creates a Model instance and binds the model properties to two labels. Code samples are here: https://gist.github.com/grantges/28241878e3886c1cec51 When looking at the compiled JavaScript, you'll notice that the generated function to update the text properties on the bound Labels is being called twice. Expectation It should only be called once per label/property


  1. Tim Poulsen 2014-05-13

    [~fmiao] would you confirm this is still happening with Alloy 1.4? Thanks.
  2. Feon Sua Xin Miao 2014-05-26

    [~skypanther] it's still happening with Alloy 1.4.0-alpha4.
  3. Feon Sua Xin Miao 2014-05-27

    PR: https://github.com/appcelerator/alloy/pull/418 Test app: https://github.com/feons/alloy/tree/ALOY-1000/test/apps/testing/ALOY-1000 Functional Test: 1. Run the test app on iOS 2. Check Resources/iphone/alloy/controllers/index.js:
        66     doClick ? $.__views.genre.addEventListener("click", doClick) : __defers["$.__views.genre!click!doClick"] = true;
        67     var __alloyId4 = function() {
        68         $.title.text = _.isFunction(Alloy.Models.book.transform) ? Alloy.Models.book.transform()["title"] : Alloy.Models.book.get("title");
        69         $.author.text = _.isFunction(Alloy.Models.book.transform) ? Alloy.Models.book.transform()["author"] : Alloy.Models.book.get("author");
        70         $.genre.text = _.isFunction(Alloy.Models.book.transform) ? Alloy.Models.book.transform()["genre"] : Alloy.Models.book.get("genre");
        71     };
        72     Alloy.Models.book.on("fetch change destroy", __alloyId4);
    3. For each property, the update function is generated once.
  4. Tim Poulsen 2014-05-28

    PR tested and merged
  5. Ewan Harris 2014-08-22

    Verified fix on: Mac OSX 10.9.4 Appcelerator Studio, build: Titanium SDK build: 3.4.0.v20140821144114 Titanium CLI, build: 3.4.0-dev Alloy: 1.5.0-dev iOS Simulator 7.1 Built the test to iOS and then checked Resources/iphone/alloy/controllers/index.js, the update function is generated once for each property.
       doClick ? $.__views.genre.addEventListener("click", doClick) : __defers["$.__views.genre!click!doClick"] = true;
           var __alloyId2 = function() {
               $.title.text = _.isFunction(Alloy.Models.book.transform) ? Alloy.Models.book.transform()["title"] : _.template("<%=book.title%>", {
                   book: Alloy.Models.book.toJSON()
               $.author.text = _.isFunction(Alloy.Models.book.transform) ? Alloy.Models.book.transform()["author"] : _.template("<%=book.author%>", {
                   book: Alloy.Models.book.toJSON()
               $.genre.text = _.isFunction(Alloy.Models.book.transform) ? Alloy.Models.book.transform()["genre"] : _.template("<%=book.genre%>", {
                   book: Alloy.Models.book.toJSON()
           Alloy.Models.book.on("fetch change destroy", __alloyId2);
    Closing ticket.

JSON Source