Created
October 3, 2012 05:10
-
-
Save brian428/3825139 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 | |
loadCompanies: -> | |
@companyService.loadCompanies().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 using a Store and returning a Promise | |
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 | |
# Service method using an Ext.Ajax call and returning a Promise | |
loadCompanies: -> | |
deferred = Ext.create( 'Deft.Deferred' ) | |
Ext.Ajax.request( | |
url: "company/loadCompanies.json" | |
success: ( response ) -> | |
records = Ext.decode( response.responseText ) | |
deferred.resolve( records ) | |
failure: ( response ) -> | |
deferred.reject( "Error loading Companies." ) | |
) | |
return deferred.promise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment