Titanium JIRA Archive
Alloy (ALOY)

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

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2014-10-28T15:14:26.000+0000
Affected Version/sn/a
Fix Version/sAlloy 1.6.0, Alloy 1.7.0
ComponentsModels
Labelsn/a
ReporterTim Poulsen
AssigneeTim Poulsen
Created2014-10-20T19:57:12.000+0000
Updated2015-02-14T02:35:25.000+0000

Description

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.

Attachments

FileDateSize
app.zip2015-02-12T20:46:47.000+00005935536

Comments

  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