Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1159] Backbone fetch() returns undefined when run from TiStudio on Titanium 3.5/Alloy 1.5.1

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionDuplicate
Resolution Date2015-02-05T15:58:11.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
LabelsTCSupportTriage
ReporterEric Thiebaut-George
AssigneeMostafizur Rahman
Created2015-02-03T09:16:18.000+0000
Updated2016-03-08T07:37:31.000+0000

Description

Titanium 3.5, Alloy 1.5.1, latest TiStudio, iPhone 5s simulator with iOS 8.1. All alloy.fetch() calls return undefined instead of a promise. The issue is in https://github.com/appcelerator/alloy/blob/1_3_X/Alloy/lib/alloy.js line 139 (latest version): extendObj.sync = function(method, model, opts) { mod.sync(method, model, opts); }; Should be: extendObj.sync = function(method, model, opts) { return mod.sync(method, model, opts); }; Note: there is a second instance of the same issue later on in the file, which exposes the same issue and needs to be fixed again.

Comments

  1. Eric Thiebaut-George 2015-02-04

    Updated description to state that there is a 2nd instance of the same issue in the same file. We hit the same issue in another part of the code and adding the return statement fixes this issue too.
  2. Mauro Parra-Miranda 2015-02-04

    Hello Eric, do you mind to provide a simple testcase that shows the issue? Then we can add your fix as suggested fix to engineering. Best Regards
  3. Eric Thiebaut-George 2015-02-04

    Hi, I won't have time to create a self-contained project but basically it happens when using a model that returns a promise and try to execute: Alloy.createModel("test").fetch().then(function(data) { Ti.API.log("info", "In then"); }).catch(function(data) { Ti.API.log("info", "In catch"); }); This used to work in older versions of Titanium but now breaks. Interestingly enough, it only breaks when compiling from TiStudio, but it works when compiling from the CLI. So the question is: is fetch() returning a value supported? This is extremely valuable when using an async adapter, as opposed to getting into callback or event hell. I actually just found someone experiencing the same issue and documenting the same fix: https://github.com/aaronksaunders/tiConnectSampleApp Look for "Hacking of alloy.js to get promises to work". So this project (tiConnectSampleApp) can be used as a sample to show the advantage of adding a return statement in these 2 places. Looking at the backbone doc for fetch(), it is supposed to return a jqXHR, so in theory it should be able to return something. It may be slightly outside of the scope of Titanium - I'll let you decide, but being able to use promises is a great advantage.
  4. Eric Thiebaut-George 2015-02-05

  5. Mauro Parra-Miranda 2015-02-05

JSON Source