-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-eventually.js
More file actions
40 lines (38 loc) · 1.27 KB
/
Copy pathangular-eventually.js
File metadata and controls
40 lines (38 loc) · 1.27 KB
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
35
36
37
38
39
40
/**
* eventuallyjs - Utility service for eventually consistent application frontends
* @version v0.0.0
* @link https://github.com/neuralaxis/eventuallyjs
* @license MIT
*/(function(window, angular) {
'use strict';
var Eventually = {
interval: 1000,
setup: function(events) {
var self = this;
for(var k in events) {
(function(n) {
var check = events[n];
var fn = function(n) {
var orig = arguments;
var args = Array.prototype.slice.call(arguments, 0, arguments.length-1);
var success = Array.prototype.slice.call(arguments, arguments.length-1)[0];
var cb = function(stop) {
if(stop) {
success();
} else {
setTimeout(function() {
fn.apply(fn, Array.prototype.slice.call(orig, 0))
}, Eventually.interval);
}
}
check.apply(check, Array.prototype.concat.call(args, [cb]));
}
self[n] = fn; // saved(id, success);
})(k);
}
}
};
angular.module('ngEventually', []).factory('Eventually', function() {
return Eventually;
});
})(window, window.angular);