/
ca-helpers.js
52 lines (41 loc) · 981 Bytes
/
ca-helpers.js
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
41
42
43
44
45
46
47
48
49
50
51
52
angular.module("ca-helpers", []);
angular.module("ca-helpers")
.factory("caHelpersApply", function($rootScope, $log) {
var apply = function(scope) {
if (!scope) { return; }
switch (scope.$$phase) {
case "$digest":
case "$apply":
$log.info("Apply not applied, current phase: ", scope.$$phase);
break;
default:
try {
scope.$apply();
} catch (e) {
$log.info("Attempted to apply, but received exception: ", e)
}
}
}
return function() {
$rootScope.apply = function() {
return apply($rootScope);
}
};
})
.run(function(caHelpersApply) {
caHelpersApply();
});
angular.module("ca-helpers")
.factory("caHelpersOnce", function($rootScope) {
var once = function(scope, event, fn) {
var removeFunction;
removeFunction = scope.$on(event, function() {
try {
fn();
} finally {
removeFunction();
}
});
}
return once;
});