[ALOY-1174] Update sync adapters to support promises in addition to callbacks
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2014-10-28T15:14:26.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Alloy 1.6.0, Alloy 1.7.0 |
Components | Models |
Labels | n/a |
Reporter | Tim Poulsen |
Assignee | Tim Poulsen |
Created | 2014-10-20T19:57:12.000+0000 |
Updated | 2015-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
File | Date | Size |
---|---|---|
app.zip | 2015-02-12T20:46:47.000+0000 | 5935536 |
Community PR for this: https://github.com/appcelerator/alloy/pull/613 Passes all tests, all models/* test apps run without issues. Merged.
Backport to 1_6_X : https://github.com/appcelerator/alloy/pull/655
Note to testers: you should be able to build any/all of the test apps that use models/collections without change or errors
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.