Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 7431735

Browse files
committed
Update TaskObject.js
1 parent 1c3920d commit 7431735

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

modules/Task/TaskObject.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@ 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.creating = $q.when(this.uploading)
24+
return this.cache('creating', () => $q.when(this.uploading)
2525
.then( () => $http.post('/api/tasks', this) ) // uploading callback
2626
.then( response => return Object.assign(this, response.data) ) // creating callback
27-
.finally( () => this.creating = null ); // state cleanup (doesn't affect chaining)
27+
.finally( () => this.creating = null ) // state cleanup (doesn't affect chaining)
28+
);
2829
}
2930

3031
update() {
3132
// wraps `this.uploading` in a promise that resolves immediately if it is `null` or waits for the promise
32-
return this.updating = $q.when(this.uploading)
33+
return this.cache('updating', () => $q.when(this.uploading)
3334
.then( () => $http.post(`/api/tasks/${this.id}`, this) ) // uploading callback
3435
.then( response => return Object.assign(this, response.data) ) // creating callback
35-
.finally( () => this.updating = null ); // state cleanup (doesn't affect chaining)
36+
.finally( () => this.updating = null ) // state cleanup (doesn't affect chaining)
37+
);
3638
}
3739

3840
/**
@@ -41,9 +43,10 @@ module.factory( 'Task', (BaseObject, $http) => {
4143
* @note Added to demonstrate clean ways to have 1 method wait for another method to finish
4244
*/
4345
upload(attachment) {
44-
return this.uploading = $http.post(`/api/attachments`, attachment)
46+
return this.cache('uploading', () => $http.post(`/api/attachments`, attachment)
4547
.then( response => this.attachments = response.data )
46-
.finally( () => this.uploading = null ); // state cleanup (doesn't affect chaining)
48+
.finally( () => this.uploading = null ) // state cleanup (doesn't affect chaining)
49+
);
4750
}
4851
}
4952

0 commit comments

Comments
 (0)