-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendOnce.js
More file actions
34 lines (30 loc) · 834 Bytes
/
sendOnce.js
File metadata and controls
34 lines (30 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
* angular-sendonce
* http://github.com/purelabs/angular-sendonce
*
* Version: 0.1.0 - 2015-05-15
* License: MIT
*/
angular.module('sendOnce', [])
.factory('sendOnce', function($q) {
return function(stateHolder, func) {
stateHolder.sending = !!stateHolder.sending;
stateHolder.sent = !!stateHolder.sent;
if (!stateHolder.sending && !stateHolder.sent) {
stateHolder.sending = true;
return func().then(
function() {
stateHolder.sending = false;
stateHolder.sent = true;
},
function() {
stateHolder.sending = false;
stateHolder.sent = false;
}
);
} else {
return $q.defer();
}
};
})
;