Titanium JIRA Archive
Alloy (ALOY)

[ALOY-1174] Update sync adapters to support promises in addition to callbacks

GitHub Issuen/a
Resolution Date2014-10-28T15:14:26.000+0000
Affected Version/sn/a
Fix Version/sAlloy 1.6.0, Alloy 1.7.0
ReporterTim Poulsen
AssigneeTim Poulsen


Per comments at [Hacking alloy to get promises to work](https://github.com/aaronksaunders/tiConnectSampleApp#hacking-of-alloyjs-to-get-promises-to-work), the core model/collection constructors could be modified simply to support using promises in addition to callbacks. As shown in [Aaron's TiConnect sample](https://github.com/aaronksaunders/tiConnectSampleApp/blob/master/app/alloy.js#L22) the change involves returning the results of the sync call. Resolving this cannot break existing apps, so extensive testing should be done on all platforms.




  1. Tim Poulsen 2014-10-28

    Community PR for this: https://github.com/appcelerator/alloy/pull/613 Passes all tests, all models/* test apps run without issues. Merged.
  2. Feon Sua Xin Miao 2015-01-13

    Backport to 1_6_X : https://github.com/appcelerator/alloy/pull/655
  3. Tim Poulsen 2015-01-13

    Note to testers: you should be able to build any/all of the test apps that use models/collections without change or errors
  4. Tim Poulsen 2015-02-12

    App that demonstrates the use of promises attached. The key is the doClick() function in the index.js controller. You'll see that it's fetching from the collection, which now has a new property of promise which contains a promise object. That object's then() method is used to display data when the JSON data source finally returns the data. If you look to the lib/alloy/sync/customAdapter.js file, you'll see that we're creating and returning a promise. Perhaps the adapter could be rewritten without the superagent library. But since it is designed to work with promises, it was easiest to adapt Aaron's sample app code keeping superagent in there.

JSON Source