@@ -21,19 +21,19 @@ module.factory( 'Task', (BaseObject, $http) => {
2121 */
2222 create ( ) {
2323 // wraps `this.uploading` in a promise that resolves immediately if it is `null` or waits for the promise
24- return this . cache ( 'creating' , ( ) => $q . when ( this . uploading )
25- . then ( ( ) => $http . post ( '/api/tasks' , this ) ) // uploading callback
26- . then ( response => return Object . assign ( this , response . data ) ) // creating callback
27- . finally ( ( ) => this . creating = null ) // state cleanup (doesn't affect chaining)
24+ return this . cache ( 'creating' , ( ) =>
25+ $q . when ( this . uploading )
26+ . then ( ( ) => $http . post ( '/api/tasks' , this ) ) // uploading callback
27+ . then ( response => return Object . assign ( this , response . data ) ) // creating callback
2828 ) ;
2929 }
3030
3131 update ( ) {
3232 // wraps `this.uploading` in a promise that resolves immediately if it is `null` or waits for the promise
33- return this . cache ( 'updating' , ( ) => $q . when ( this . uploading )
34- . then ( ( ) => $http . post ( `/api/tasks/ ${ this . id } ` , this ) ) // uploading callback
35- . then ( response => return Object . assign ( this , response . data ) ) // creating callback
36- . finally ( ( ) => this . updating = null ) // state cleanup (doesn't affect chaining)
33+ return this . cache ( 'updating' , ( ) =>
34+ $q . when ( this . uploading )
35+ . then ( ( ) => $http . post ( `/api/tasks/ ${ this . id } ` , this ) ) // uploading callback
36+ . then ( response => return Object . assign ( this , response . data ) ) // creating callback
3737 ) ;
3838 }
3939
@@ -43,9 +43,9 @@ module.factory( 'Task', (BaseObject, $http) => {
4343 * @note Added to demonstrate clean ways to have 1 method wait for another method to finish
4444 */
4545 upload ( attachment ) {
46- return this . cache ( 'uploading' , ( ) => $http . post ( `/api/attachments` , attachment )
47- . then ( response => this . attachments = response . data )
48- . finally ( ( ) => this . uploading = null ) // state cleanup (doesn't affect chaining )
46+ return this . cache ( 'uploading' , ( ) =>
47+ $http . post ( `/api/ attachments` , attachment )
48+ . then ( response => this . attachments = response . data )
4949 ) ;
5050 }
5151 }
0 commit comments