@angular-wave/angular.ts 0.4.2 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/angular-ts.esm.js +2 -2
- package/dist/angular-ts.umd.js +12 -2
- package/index.html +74 -3
- package/package.json +7 -7
- package/src/angular.spec.js +1 -269
- package/src/animations/animate-css-driver.js +2 -2
- package/src/animations/animate-css.js +12 -21
- package/src/animations/animate-js-driver.js +1 -3
- package/src/animations/animate-js.js +4 -4
- package/src/animations/animate-queue.js +23 -23
- package/src/animations/animate-runner.js +4 -8
- package/src/animations/animate.md +1 -1
- package/src/animations/animate.spec.js +0 -21
- package/src/animations/animation.js +4 -4
- package/src/animations/shared.js +14 -12
- package/src/binding.spec.js +0 -1
- package/src/core/cache/cache.js +2 -29
- package/src/core/compile/attributes.js +2 -3
- package/src/core/compile/compile.js +260 -245
- package/src/core/compile/compile.spec.js +63 -317
- package/src/core/compile/compile.test.js +1 -1
- package/src/core/controller/controller.js +2 -0
- package/src/core/di/injector.md +1 -1
- package/src/core/di/injector.spec.js +0 -2
- package/src/core/di/internal-injector.js +2 -1
- package/src/core/interpolate/interpolate.js +16 -3
- package/src/core/interpolate/interpolate.spec.js +70 -16
- package/src/core/location/location.js +0 -2
- package/src/core/location/location.spec.js +27 -27
- package/src/core/{scope/scope.html → model/model.html} +1 -1
- package/src/core/model/model.js +944 -0
- package/src/core/model/model.spec.js +3012 -0
- package/src/core/on.spec.js +0 -7
- package/src/core/parse/interpreter.js +10 -7
- package/src/core/parse/parse.js +28 -7
- package/src/core/parse/parse.spec.js +95 -91
- package/src/core/prop.spec.js +4 -60
- package/src/core/sce/sce.js +1 -2
- package/src/core/sce/sce.spec.js +0 -8
- package/src/core/scope/scope.js +62 -32
- package/src/core/scope/scope.spec.js +25 -1960
- package/src/directive/aria/aria.js +3 -6
- package/src/directive/aria/aria.spec.js +0 -87
- package/src/directive/attrs/attrs.spec.js +0 -5
- package/src/directive/{list/list.test.js → attrs/attrs.test.js} +1 -1
- package/src/{core/q/q.html → directive/attrs/boolean.html} +1 -1
- package/src/directive/attrs/boolean.spec.js +0 -15
- package/src/{core/q/q.test.js → directive/attrs/boolean.test.js} +1 -2
- package/src/{core/timeout/timeout.html → directive/attrs/element-style.html} +4 -1
- package/src/directive/attrs/element-style.spec.js +0 -8
- package/src/{core/scope/scope.test.js → directive/attrs/element-style.test.js} +1 -2
- package/src/directive/attrs/src.spec.js +0 -7
- package/src/directive/bind/bind.spec.js +0 -33
- package/src/directive/bind/bing-html.spec.js +1 -4
- package/src/{core/interval/interval.html → directive/channel/channel.html} +1 -1
- package/src/directive/channel/channel.js +29 -0
- package/src/directive/channel/channel.spec.js +52 -0
- package/src/directive/channel/channel.test.js +9 -0
- package/src/directive/class/class.js +3 -3
- package/src/directive/class/class.spec.js +9 -75
- package/src/directive/controller/controller.spec.js +0 -13
- package/src/directive/events/click.spec.js +0 -3
- package/src/directive/events/event.spec.js +0 -6
- package/src/directive/form/form.js +14 -22
- package/src/directive/form/form.spec.js +0 -65
- package/src/directive/if/if.spec.js +2 -7
- package/src/directive/if/if.test.js +1 -2
- package/src/directive/include/include.js +2 -2
- package/src/directive/include/include.spec.js +8 -59
- package/src/directive/init/init.js +6 -2
- package/src/directive/init/init.spec.js +0 -2
- package/src/directive/input/input.js +1 -2
- package/src/directive/input/input.spec.js +191 -331
- package/src/directive/messages/messages.spec.js +4 -35
- package/src/directive/model/model.js +30 -42
- package/src/directive/model/model.spec.js +2 -49
- package/src/directive/model-options/model-options.js +22 -26
- package/src/directive/model-options/model-options.spec.js +0 -6
- package/src/directive/non-bindable/non-bindable.spec.js +0 -1
- package/src/directive/observe/observe.js +0 -1
- package/src/directive/observe/observe.spec.js +0 -1
- package/src/directive/options/options.js +1 -3
- package/src/directive/options/options.spec.js +3 -38
- package/src/directive/ref/href.spec.js +0 -15
- package/src/directive/repeat/repeat.js +2 -2
- package/src/directive/repeat/repeat.spec.js +56 -192
- package/src/directive/script/script.spec.js +0 -2
- package/src/directive/select/select.js +3 -3
- package/src/directive/select/select.spec.js +9 -106
- package/src/directive/show-hide/show-hide.js +2 -2
- package/src/directive/show-hide/show-hide.spec.js +8 -19
- package/src/directive/style/style.spec.js +0 -7
- package/src/directive/switch/switch.js +1 -2
- package/src/directive/switch/switch.spec.js +5 -5
- package/src/directive/validators/validators.spec.js +0 -1
- package/src/loader.js +0 -1
- package/src/public.js +75 -80
- package/src/router/common/coreservices.js +0 -2
- package/src/router/directives/state-directives.js +24 -30
- package/src/router/directives/state-directives.spec.js +0 -83
- package/src/router/directives/view-directive.js +6 -15
- package/src/router/directives/view-directive.spec.js +25 -71
- package/src/router/hooks/lazy-load.js +2 -2
- package/src/router/hooks/views.js +3 -5
- package/src/router/resolve/resolvable.js +3 -6
- package/src/router/resolve/resolve-context.js +2 -2
- package/src/router/state/state-service.js +4 -4
- package/src/router/state/state.spec.js +2 -5
- package/src/router/state/views.js +9 -12
- package/src/router/template-factory.js +3 -6
- package/src/router/template-factory.spec.js +0 -4
- package/src/router/transition/transition-hook.js +1 -1
- package/src/router/transition/transition.js +1 -1
- package/src/router/url/url-service.js +2 -8
- package/src/router/url/url-service.spec.js +3 -4
- package/src/router/view-hook.spec.js +2 -2
- package/src/router/view-scroll.js +4 -6
- package/src/services/http/http.js +11 -15
- package/src/services/http/http.spec.js +30 -31
- package/src/services/http/template-request.spec.js +0 -10
- package/src/services/http-backend/http-backend.js +19 -17
- package/src/services/http-backend/http-backend.spec.js +3 -3
- package/src/services/template-request.js +2 -4
- package/src/shared/common.js +6 -10
- package/src/shared/jqlite/jqlite.js +14 -15
- package/src/shared/jqlite/jqlite.spec.js +2 -2
- package/src/shared/utils.js +15 -92
- package/types/core/cache/cache.d.ts +1 -1
- package/types/core/model/model.d.ts +204 -0
- package/types/core/parse/parse.d.ts +26 -0
- package/types/core/scope/scope.d.ts +22 -21
- package/types/directive/channel/channel.d.ts +11 -0
- package/types/directive/form/form.d.ts +1 -0
- package/types/shared/common.d.ts +0 -1
- package/types/shared/utils.d.ts +0 -35
- package/src/core/interval/interval-factory.js +0 -50
- package/src/core/interval/interval.js +0 -77
- package/src/core/interval/interval.md +0 -123
- package/src/core/interval/interval.spec.js +0 -280
- package/src/core/q/q.js +0 -472
- package/src/core/q/q.md +0 -211
- package/src/core/q/q.spec.js +0 -2748
- package/src/core/timeout/timeout.js +0 -109
- package/src/core/timeout/timeout.spec.js +0 -354
- package/src/core/timeout/timout.test.js +0 -12
- package/src/directive/list/list.html +0 -18
- package/src/directive/list/list.js +0 -46
- package/src/directive/list/list.md +0 -22
- package/src/directive/list/list.spec.js +0 -172
- package/types/directive/list/list.d.ts +0 -4
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { isDefined, sliceArgs } from "../../shared/utils";
|
|
2
|
-
|
|
3
|
-
export function $IntervalFactoryProvider() {
|
|
4
|
-
this.$get = [
|
|
5
|
-
"$q",
|
|
6
|
-
"$rootScope",
|
|
7
|
-
/**
|
|
8
|
-
* @param {*} $q
|
|
9
|
-
* @param {import('../scope/scope').Scope} $rootScope
|
|
10
|
-
* @returns
|
|
11
|
-
*/
|
|
12
|
-
function ($q, $rootScope) {
|
|
13
|
-
return function intervalFactory(setIntervalFn, clearIntervalFn) {
|
|
14
|
-
return function intervalFn(fn, delay, count) {
|
|
15
|
-
const hasParams = arguments.length > 4;
|
|
16
|
-
const args = hasParams ? sliceArgs(arguments, 4) : [];
|
|
17
|
-
let iteration = 0;
|
|
18
|
-
const deferred = $q.defer();
|
|
19
|
-
const { promise } = deferred;
|
|
20
|
-
|
|
21
|
-
count = isDefined(count) ? count : 0;
|
|
22
|
-
|
|
23
|
-
function callback() {
|
|
24
|
-
if (!hasParams) {
|
|
25
|
-
fn(iteration);
|
|
26
|
-
} else {
|
|
27
|
-
fn.apply(null, args);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function tick() {
|
|
32
|
-
$rootScope.$evalAsync(callback);
|
|
33
|
-
|
|
34
|
-
iteration++;
|
|
35
|
-
|
|
36
|
-
if (count > 0 && iteration >= count) {
|
|
37
|
-
deferred.resolve(iteration);
|
|
38
|
-
clearIntervalFn(promise.$$intervalId);
|
|
39
|
-
}
|
|
40
|
-
$rootScope.$apply();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
promise.$$intervalId = setIntervalFn(tick, delay, deferred);
|
|
44
|
-
|
|
45
|
-
return promise;
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
];
|
|
50
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { markQExceptionHandled } from "../q/q";
|
|
2
|
-
import { minErr } from "../../shared/utils";
|
|
3
|
-
|
|
4
|
-
const $intervalMinErr = minErr("$interval");
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @typedef {number} IntervalId
|
|
8
|
-
* Interval ID which uniquely identifies the interval and can be used to cancel it
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @type {Map<IntervalId, import("../q/q").Deferred<any>>}
|
|
13
|
-
*/
|
|
14
|
-
const intervals = new Map();
|
|
15
|
-
|
|
16
|
-
export function IntervalProvider() {
|
|
17
|
-
this.$get = [
|
|
18
|
-
"$$intervalFactory",
|
|
19
|
-
// TODO Add type
|
|
20
|
-
function ($$intervalFactory) {
|
|
21
|
-
/**
|
|
22
|
-
* @param {TimerHandler} tick
|
|
23
|
-
* @param {number} delay
|
|
24
|
-
* @param {import("../q/q").Deferred<any>} deferred
|
|
25
|
-
* @returns {IntervalId} - This method returns an interval ID which uniquely identifies the interval
|
|
26
|
-
*/
|
|
27
|
-
function setIntervalFn(tick, delay, deferred) {
|
|
28
|
-
const id = window.setInterval(tick, delay);
|
|
29
|
-
intervals.set(id, deferred);
|
|
30
|
-
return id;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**s
|
|
34
|
-
* @param {IntervalId} id
|
|
35
|
-
*/
|
|
36
|
-
function clearIntervalFn(id) {
|
|
37
|
-
window.clearInterval(id);
|
|
38
|
-
intervals.delete(id);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const interval = $$intervalFactory(setIntervalFn, clearIntervalFn);
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Cancels a task associated with the `promise`.
|
|
45
|
-
*
|
|
46
|
-
* @param {!import("../q/q").QPromise<any>} promise returned by the `$interval` function.
|
|
47
|
-
* @returns {boolean} Returns `true` if the task was successfully canceled.
|
|
48
|
-
*/
|
|
49
|
-
interval.cancel = function (promise) {
|
|
50
|
-
if (!promise) return false;
|
|
51
|
-
|
|
52
|
-
if (!Object.prototype.hasOwnProperty.call(promise, "$$intervalId")) {
|
|
53
|
-
throw $intervalMinErr(
|
|
54
|
-
"badprom",
|
|
55
|
-
"`$interval.cancel()` called with a promise that was not generated by `$interval()`.",
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (!intervals.has(promise.$$intervalId)) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const id = promise.$$intervalId;
|
|
64
|
-
const deferred = intervals.get(id);
|
|
65
|
-
|
|
66
|
-
// Interval cancels should not report an unhandled promise.
|
|
67
|
-
markQExceptionHandled(deferred.promise);
|
|
68
|
-
deferred.reject("canceled");
|
|
69
|
-
clearIntervalFn(id);
|
|
70
|
-
|
|
71
|
-
return true;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
return interval;
|
|
75
|
-
},
|
|
76
|
-
];
|
|
77
|
-
}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
_ @ngdoc service
|
|
3
|
-
_ @name $interval
|
|
4
|
-
*
|
|
5
|
-
* @description
|
|
6
|
-
* AngularJS's wrapper for `window.setInterval`. The `fn` function is executed every `delay`
|
|
7
|
-
* milliseconds.
|
|
8
|
-
*
|
|
9
|
-
* The return value of registering an interval function is a promise. This promise will be
|
|
10
|
-
* notified upon each tick of the interval, and will be resolved after `count` iterations, or
|
|
11
|
-
* run indefinitely if `count` is not defined. The value of the notification will be the
|
|
12
|
-
* number of iterations that have run.
|
|
13
|
-
* To cancel an interval, call `$interval.cancel(promise)`.
|
|
14
|
-
*
|
|
15
|
-
* In tests you can use {@link ngMock.$interval#flush `$interval.flush(millis)`} to
|
|
16
|
-
* move forward by `millis` milliseconds and trigger any functions scheduled to run in that
|
|
17
|
-
_ time.
|
|
18
|
-
_
|
|
19
|
-
_ <div class="alert alert-warning">
|
|
20
|
-
_ **Note\*_: Intervals created by this service must be explicitly destroyed when you are finished
|
|
21
|
-
_ with them. In particular they are not automatically destroyed when a controller's scope or a
|
|
22
|
-
_ directive's element are destroyed.
|
|
23
|
-
_ You should take this into consideration and make sure to always cancel the interval at the
|
|
24
|
-
_ appropriate moment. See the example below for more details on how and when to do this.
|
|
25
|
-
_ </div> \*
|
|
26
|
-
_ @param {function()} fn A function that should be called repeatedly. If no additional arguments
|
|
27
|
-
_ are passed (see below), the function is called with the current iteration count.
|
|
28
|
-
_ @param {number} delay Number of milliseconds between each function call.
|
|
29
|
-
_ @param {number=} [count=0] Number of times to repeat. If not set, or 0, will repeat
|
|
30
|
-
_ indefinitely.
|
|
31
|
-
_ @param {boolean=} [invokeApply=true] If set to `false` skips model dirty checking, otherwise
|
|
32
|
-
_ will invoke `fn` within the {@link ng.$rootScope.Scope#$apply $apply} block.
|
|
33
|
-
_ @param {..._=} Pass additional parameters to the executed function.
|
|
34
|
-
_ @returns {promise} A promise which will be notified on each iteration. It will resolve once all iterations of the interval complete. \*
|
|
35
|
-
_ @example
|
|
36
|
-
_ <example module="intervalExample" name="interval-service">
|
|
37
|
-
_ <file name="index.html">
|
|
38
|
-
_ <script>
|
|
39
|
-
_ angular.module('intervalExample', [])
|
|
40
|
-
_ .controller('ExampleController', ['$scope', '$interval',
|
|
41
|
-
|
|
42
|
-
- function($scope, $interval) {
|
|
43
|
-
- $scope.format = 'M/d/yy h:mm:ss a';
|
|
44
|
-
- $scope.blood_1 = 100;
|
|
45
|
-
- $scope.blood_2 = 120;
|
|
46
|
-
-
|
|
47
|
-
- let stop;
|
|
48
|
-
- $scope.fight = function() {
|
|
49
|
-
- // Don't start a new fight if we are already fighting
|
|
50
|
-
- if ( angular.isDefined(stop) ) return;
|
|
51
|
-
-
|
|
52
|
-
- stop = $interval(function() {
|
|
53
|
-
- if ($scope.blood_1 > 0 && $scope.blood_2 > 0) {
|
|
54
|
-
- $scope.blood_1 = $scope.blood_1 - 3;
|
|
55
|
-
- $scope.blood_2 = $scope.blood_2 - 4;
|
|
56
|
-
- } else {
|
|
57
|
-
- $scope.stopFight();
|
|
58
|
-
- }
|
|
59
|
-
- }, 100);
|
|
60
|
-
- };
|
|
61
|
-
-
|
|
62
|
-
- $scope.stopFight = function() {
|
|
63
|
-
- if (angular.isDefined(stop)) {
|
|
64
|
-
- $interval.cancel(stop);
|
|
65
|
-
- stop = undefined;
|
|
66
|
-
- }
|
|
67
|
-
- };
|
|
68
|
-
-
|
|
69
|
-
- $scope.resetFight = function() {
|
|
70
|
-
- $scope.blood_1 = 100;
|
|
71
|
-
- $scope.blood_2 = 120;
|
|
72
|
-
- };
|
|
73
|
-
-
|
|
74
|
-
- $scope.$on('$destroy', function() {
|
|
75
|
-
- // Make sure that the interval is destroyed too
|
|
76
|
-
- $scope.stopFight();
|
|
77
|
-
- });
|
|
78
|
-
- }])
|
|
79
|
-
_ // Register the 'myCurrentTime' directive factory method.
|
|
80
|
-
_ // We inject $interval and dateFilter service since the factory method is DI.
|
|
81
|
-
* .directive('myCurrentTime', ['$interval', 'dateFilter',
|
|
82
|
-
_ function($interval, dateFilter) {
|
|
83
|
-
_ // return the directive link function. (compile function not needed)
|
|
84
|
-
_ return function(scope, element, attrs) {
|
|
85
|
-
_ let format, // date format
|
|
86
|
-
_ stopTime; // so that we can cancel the time updates
|
|
87
|
-
_
|
|
88
|
-
_ // used to update the UI
|
|
89
|
-
_ function updateTime() {
|
|
90
|
-
_ element.text(dateFilter(new Date(), format));
|
|
91
|
-
_ } \*
|
|
92
|
-
_ // watch the expression, and update the UI on change.
|
|
93
|
-
_ scope.$watch(attrs.myCurrentTime, function(value) {
|
|
94
|
-
* format = value;
|
|
95
|
-
* updateTime();
|
|
96
|
-
* });
|
|
97
|
-
*
|
|
98
|
-
* stopTime = $interval(updateTime, 1000);
|
|
99
|
-
*
|
|
100
|
-
* // listen on DOM destroy (removal) event, and cancel the next UI update
|
|
101
|
-
* // to prevent updating time after the DOM element was removed.
|
|
102
|
-
* element.on('$destroy', function() {
|
|
103
|
-
_ $interval.cancel(stopTime);
|
|
104
|
-
_ });
|
|
105
|
-
_ }
|
|
106
|
-
_ }]);
|
|
107
|
-
_ </script>
|
|
108
|
-
_
|
|
109
|
-
_ <div>
|
|
110
|
-
_ <div ng-controller="ExampleController">
|
|
111
|
-
_ <label>Date format: <input ng-model="format"></label> <hr/>
|
|
112
|
-
_ Current time is: <span my-current-time="format"></span>
|
|
113
|
-
_ <hr/>
|
|
114
|
-
_ Blood 1 : <font color='red'>{{blood_1}}</font>
|
|
115
|
-
_ Blood 2 : <font color='red'>{{blood_2}}</font>
|
|
116
|
-
_ <button type="button" data-ng-click="fight()">Fight</button>
|
|
117
|
-
_ <button type="button" data-ng-click="stopFight()">StopFight</button>
|
|
118
|
-
_ <button type="button" data-ng-click="resetFight()">resetFight</button>
|
|
119
|
-
_ </div>
|
|
120
|
-
_ </div> \*
|
|
121
|
-
_ </file>
|
|
122
|
-
_ </example>
|
|
123
|
-
\*/
|
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
import { Angular } from "../../loader";
|
|
2
|
-
import { createInjector } from "../di/injector";
|
|
3
|
-
import { wait } from "../../shared/test-utils";
|
|
4
|
-
|
|
5
|
-
describe("$interval", () => {
|
|
6
|
-
let injector;
|
|
7
|
-
let $interval;
|
|
8
|
-
let $rootScope;
|
|
9
|
-
let errors;
|
|
10
|
-
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
errors = [];
|
|
13
|
-
window.angular = new Angular();
|
|
14
|
-
window.angular
|
|
15
|
-
.module("myModule", ["ng"])
|
|
16
|
-
.decorator("$exceptionHandler", () => {
|
|
17
|
-
return (exception) => {
|
|
18
|
-
errors.push(exception);
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
injector = createInjector(["myModule"]);
|
|
22
|
-
|
|
23
|
-
$interval = injector.get("$interval");
|
|
24
|
-
$rootScope = injector.get("$rootScope");
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("should run tasks repeatedly", async () => {
|
|
28
|
-
let counter = 0;
|
|
29
|
-
$interval(() => {
|
|
30
|
-
counter++;
|
|
31
|
-
}, 1);
|
|
32
|
-
expect(counter).toBe(0);
|
|
33
|
-
await wait(15);
|
|
34
|
-
expect(counter).toBeGreaterThanOrEqual(1);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("should call $apply after each task is executed", (done) => {
|
|
38
|
-
const applySpy = spyOn($rootScope, "$apply").and.callThrough();
|
|
39
|
-
|
|
40
|
-
$interval(() => {}, 1);
|
|
41
|
-
expect(applySpy).not.toHaveBeenCalled();
|
|
42
|
-
|
|
43
|
-
setTimeout(() => {
|
|
44
|
-
expect(applySpy).toHaveBeenCalled();
|
|
45
|
-
}, 3);
|
|
46
|
-
|
|
47
|
-
applySpy.calls.reset();
|
|
48
|
-
|
|
49
|
-
$interval(() => {}, 1);
|
|
50
|
-
$interval(() => {}, 1);
|
|
51
|
-
|
|
52
|
-
setTimeout(() => {
|
|
53
|
-
expect(applySpy).toHaveBeenCalledTimes(3);
|
|
54
|
-
done();
|
|
55
|
-
}, 1);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("should allow you to specify a number of iterations", async () => {
|
|
59
|
-
let counter = 0;
|
|
60
|
-
$interval(
|
|
61
|
-
() => {
|
|
62
|
-
counter++;
|
|
63
|
-
},
|
|
64
|
-
1,
|
|
65
|
-
2,
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
await wait(15);
|
|
69
|
-
expect(counter).toBe(2);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("should allow you to specify a number of arguments", (done) => {
|
|
73
|
-
const task1 = jasmine.createSpy("task1");
|
|
74
|
-
const task2 = jasmine.createSpy("task2");
|
|
75
|
-
const task3 = jasmine.createSpy("task3");
|
|
76
|
-
$interval(task1, 1, 2, true, "Task1");
|
|
77
|
-
$interval(task2, 1, 2, true, "Task2");
|
|
78
|
-
$interval(task3, 1, 2, true, "I", "am", "a", "Task3", "spy");
|
|
79
|
-
|
|
80
|
-
setTimeout(() => {
|
|
81
|
-
expect(task1).toHaveBeenCalledWith("Task1");
|
|
82
|
-
expect(task2).toHaveBeenCalledWith("Task2");
|
|
83
|
-
expect(task3).toHaveBeenCalledWith("I", "am", "a", "Task3", "spy");
|
|
84
|
-
}, 1);
|
|
85
|
-
|
|
86
|
-
task1.calls.reset();
|
|
87
|
-
task2.calls.reset();
|
|
88
|
-
task3.calls.reset();
|
|
89
|
-
|
|
90
|
-
setTimeout(() => {
|
|
91
|
-
expect(task1).toHaveBeenCalledWith("Task1");
|
|
92
|
-
expect(task2).toHaveBeenCalledWith("Task2");
|
|
93
|
-
expect(task3).toHaveBeenCalledWith("I", "am", "a", "Task3", "spy");
|
|
94
|
-
done();
|
|
95
|
-
}, 1);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it("should return a promise which will be updated with the count on each iteration", async () => {
|
|
99
|
-
const log = [];
|
|
100
|
-
const promise = $interval(() => {
|
|
101
|
-
log.push("tick");
|
|
102
|
-
}, 1);
|
|
103
|
-
|
|
104
|
-
promise.then(
|
|
105
|
-
(value) => {
|
|
106
|
-
log.push(`promise success: ${value}`);
|
|
107
|
-
},
|
|
108
|
-
(err) => {
|
|
109
|
-
log.push(`promise error: ${err}`);
|
|
110
|
-
},
|
|
111
|
-
(note) => {
|
|
112
|
-
log.push(`promise update: ${note}`);
|
|
113
|
-
},
|
|
114
|
-
);
|
|
115
|
-
expect(log).toEqual([]);
|
|
116
|
-
|
|
117
|
-
await wait(5);
|
|
118
|
-
expect(log[0]).toEqual("tick");
|
|
119
|
-
expect(log[1]).toEqual("tick");
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("should return a promise which will be resolved after the specified number of iterations", async () => {
|
|
123
|
-
const log = [];
|
|
124
|
-
const promise = $interval(
|
|
125
|
-
() => {
|
|
126
|
-
log.push("tick");
|
|
127
|
-
},
|
|
128
|
-
1,
|
|
129
|
-
2,
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
promise.then(
|
|
133
|
-
(value) => {
|
|
134
|
-
log.push(`promise success: ${value}`);
|
|
135
|
-
},
|
|
136
|
-
(err) => {
|
|
137
|
-
log.push(`promise error: ${err}`);
|
|
138
|
-
},
|
|
139
|
-
);
|
|
140
|
-
expect(log).toEqual([]);
|
|
141
|
-
await wait(15);
|
|
142
|
-
expect(log).toEqual(["tick", "tick", "promise success: 2"]);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
describe("exception handling", () => {
|
|
146
|
-
it("should delegate exception to the $exceptionHandler service", (done) => {
|
|
147
|
-
errors = [];
|
|
148
|
-
$interval(() => {
|
|
149
|
-
throw "Test Error";
|
|
150
|
-
}, 10);
|
|
151
|
-
|
|
152
|
-
setTimeout(() => {
|
|
153
|
-
expect(errors).toContain("Test Error");
|
|
154
|
-
done();
|
|
155
|
-
}, 20);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("should call $apply even if an exception is thrown in callback", (done) => {
|
|
159
|
-
const applySpy = spyOn($rootScope, "$apply").and.callThrough();
|
|
160
|
-
|
|
161
|
-
$interval(() => {
|
|
162
|
-
throw "Test Error2";
|
|
163
|
-
}, 10);
|
|
164
|
-
expect(applySpy).not.toHaveBeenCalled();
|
|
165
|
-
|
|
166
|
-
setTimeout(() => {
|
|
167
|
-
expect(applySpy).toHaveBeenCalled();
|
|
168
|
-
done();
|
|
169
|
-
}, 11);
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
describe("cancel", () => {
|
|
174
|
-
it("should cancel tasks", (done) => {
|
|
175
|
-
const task1 = jasmine.createSpy("task1", 1);
|
|
176
|
-
const task2 = jasmine.createSpy("task2", 1);
|
|
177
|
-
const task3 = jasmine.createSpy("task3", 1);
|
|
178
|
-
let promise1;
|
|
179
|
-
let promise3;
|
|
180
|
-
|
|
181
|
-
promise1 = $interval(task1, 2);
|
|
182
|
-
$interval(task2, 1);
|
|
183
|
-
promise3 = $interval(task3, 3);
|
|
184
|
-
|
|
185
|
-
$interval.cancel(promise3);
|
|
186
|
-
$interval.cancel(promise1);
|
|
187
|
-
setTimeout(() => {
|
|
188
|
-
expect(task1).not.toHaveBeenCalled();
|
|
189
|
-
expect(task2).toHaveBeenCalled();
|
|
190
|
-
expect(task3).not.toHaveBeenCalled();
|
|
191
|
-
done();
|
|
192
|
-
}, 1);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it("should cancel the promise", (done) => {
|
|
196
|
-
const promise = $interval(() => {}, 1);
|
|
197
|
-
const log = [];
|
|
198
|
-
promise.then(
|
|
199
|
-
(value) => {
|
|
200
|
-
log.push(`promise success: ${value}`);
|
|
201
|
-
},
|
|
202
|
-
(err) => {
|
|
203
|
-
log.push(`promise error: ${err}`);
|
|
204
|
-
},
|
|
205
|
-
);
|
|
206
|
-
expect(log).toEqual([]);
|
|
207
|
-
|
|
208
|
-
setTimeout(() => {
|
|
209
|
-
$interval.cancel(promise);
|
|
210
|
-
}, 1);
|
|
211
|
-
|
|
212
|
-
setTimeout(() => {
|
|
213
|
-
$rootScope.$apply(); // For resolving the promise -
|
|
214
|
-
// necessary since q uses $rootScope.evalAsync.
|
|
215
|
-
|
|
216
|
-
expect(log).toEqual(["promise error: canceled"]);
|
|
217
|
-
done();
|
|
218
|
-
}, 2);
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
it("should return true if a task was successfully canceled", (done) => {
|
|
222
|
-
const task1 = jasmine.createSpy("task1");
|
|
223
|
-
const task2 = jasmine.createSpy("task2");
|
|
224
|
-
let promise1;
|
|
225
|
-
let promise2;
|
|
226
|
-
|
|
227
|
-
promise1 = $interval(task1, 1, 1);
|
|
228
|
-
setTimeout(() => {
|
|
229
|
-
promise2 = $interval(task2, 1, 1);
|
|
230
|
-
|
|
231
|
-
expect($interval.cancel(promise1)).toBe(false);
|
|
232
|
-
expect($interval.cancel(promise2)).toBe(true);
|
|
233
|
-
done();
|
|
234
|
-
}, 1);
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
it("should not throw an error when given an undefined promise", () => {
|
|
238
|
-
expect($interval.cancel()).toBe(false);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it("should throw an error when given a non-$interval promise", () => {
|
|
242
|
-
const promise = $interval(() => {}).then(() => {});
|
|
243
|
-
expect(() => {
|
|
244
|
-
$interval.cancel(promise);
|
|
245
|
-
}).toThrowError(/badprom/);
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it("should not trigger digest when cancelled", () => {
|
|
249
|
-
const watchSpy = jasmine.createSpy("watchSpy");
|
|
250
|
-
$rootScope.$watch(watchSpy);
|
|
251
|
-
|
|
252
|
-
const t = $interval();
|
|
253
|
-
$interval.cancel(t);
|
|
254
|
-
expect(watchSpy).not.toHaveBeenCalled();
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
describe("$window delegation", () => {
|
|
259
|
-
it("should use $window.setInterval instead of the global function", () => {
|
|
260
|
-
const setIntervalSpy = spyOn(window, "setInterval");
|
|
261
|
-
|
|
262
|
-
$interval(() => {}, 1);
|
|
263
|
-
expect(setIntervalSpy).toHaveBeenCalled();
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
it("should use $window.clearInterval instead of the global function", (done) => {
|
|
267
|
-
const clearIntervalSpy = spyOn(window, "clearInterval");
|
|
268
|
-
|
|
269
|
-
$interval(() => {}, 1, 1);
|
|
270
|
-
setTimeout(() => {
|
|
271
|
-
expect(clearIntervalSpy).toHaveBeenCalled();
|
|
272
|
-
|
|
273
|
-
clearIntervalSpy.calls.reset();
|
|
274
|
-
$interval.cancel($interval(() => {}, 1));
|
|
275
|
-
expect(clearIntervalSpy).toHaveBeenCalled();
|
|
276
|
-
done();
|
|
277
|
-
}, 1);
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
});
|