Created
October 3, 2012 05:11
-
-
Save brian428/3825143 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Using a Promise for a chain of async calls | |
loadInitialData: -> | |
@companyService.loadInitialData().then( | |
success: ( records ) -> | |
# Do something with results | |
failure: ( error ) -> | |
# Do something with the error | |
).always( -> | |
# Do something whether the call succeeded or failed | |
) | |
# Service method aggregating Promises for separate calls and returning a single Promise | |
loadInitialData: -> | |
return Deft.Promise.all( [ | |
@loadCompanies() | |
@loadFeaturedProducts() | |
] ) | |
loadCompanies: -> | |
deferred = Ext.create( 'Deft.Deferred' ) | |
@companyStore.load( | |
callback: ( records, operation, success ) -> | |
if( success ) | |
deferred.resolve( records ) | |
else | |
deferred.reject( "Error loading Companies." ) | |
) | |
return deferred.promise | |
loadFeaturedProducts: -> | |
deferred = Ext.create( 'Deft.Deferred' ) | |
@featuredProductStore.load( | |
callback: ( records, operation, success ) -> | |
if( success ) | |
deferred.resolve( records ) | |
else | |
deferred.reject( "Error loading Products." ) | |
) | |
return deferred.promise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment