@angular-wave/angular.ts 0.4.3 → 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.umd.js +10 -0
- package/index.html +74 -3
- package/package.json +1 -1
- package/src/angular.spec.js +0 -5
- package/src/animations/animate-css.js +5 -13
- package/src/animations/animate-queue.js +22 -21
- 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 +1 -1
- package/src/binding.spec.js +0 -1
- package/src/core/cache/cache.js +2 -29
- package/src/core/compile/compile.js +26 -27
- package/src/core/compile/compile.spec.js +17 -266
- 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/interval/interval.test.js +1 -1
- 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 +26 -5
- package/src/core/parse/parse.spec.js +95 -91
- package/src/core/prop.spec.js +4 -60
- package/src/core/sce/sce.spec.js +0 -8
- package/src/core/scope/scope.js +61 -30
- 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/attrs/boolean.spec.js +0 -15
- package/src/directive/attrs/element-style.spec.js +0 -8
- 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 +0 -3
- package/src/{core/q/q.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/{list/list.test.js → channel/channel.test.js} +2 -4
- 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 +2 -3
- package/src/directive/form/form.spec.js +0 -65
- package/src/directive/if/if.spec.js +0 -4
- 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.spec.js +0 -136
- package/src/directive/messages/messages.spec.js +4 -35
- package/src/directive/model/model.js +18 -25
- package/src/directive/model/model.spec.js +2 -49
- 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.spec.js +0 -34
- package/src/directive/ref/href.spec.js +0 -15
- package/src/directive/repeat/repeat.spec.js +8 -135
- package/src/directive/script/script.spec.js +0 -2
- package/src/directive/select/select.js +3 -3
- package/src/directive/select/select.spec.js +0 -96
- 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.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 +6 -14
- package/src/router/directives/state-directives.spec.js +0 -83
- package/src/router/directives/view-directive.js +4 -13
- 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 +7 -10
- 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/view-hook.spec.js +2 -2
- package/src/router/view-scroll.js +4 -6
- package/src/services/http/http.js +6 -9
- 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.spec.js +3 -3
- package/src/services/template-request.js +2 -4
- package/src/shared/common.js +1 -2
- package/src/shared/jqlite/jqlite.js +0 -3
- 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/src/core/interval/interval-factory.js +0 -50
- package/src/core/interval/interval.html +0 -18
- 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/q/q.test.js +0 -12
- package/src/core/scope/scope.test.js +0 -12
- package/src/core/timeout/timeout.html +0 -18
- 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
|
@@ -4,10 +4,19 @@
|
|
|
4
4
|
* @property {boolean} constant - Indicates if the expression is constant.
|
|
5
5
|
* @property {boolean} [isPure]
|
|
6
6
|
* @property {boolean} oneTime
|
|
7
|
+
* @property {import("./interpreter.js").DecoratedASTNode} decoratedNode
|
|
7
8
|
* @property {function(import('../scope/scope').Scope, import('../scope/scope').WatchListener, boolean, CompiledExpression, string | ((scope: import('../scope/scope').Scope) => any) | CompiledExpression): any} [$$watchDelegate]
|
|
8
9
|
* @property {any[]|Function} inputs
|
|
9
10
|
* @property {function(any, any): any} [assign] - Assigns a value to a context. If value is not provided,
|
|
10
11
|
*/
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {Object} CompiledExpressionHandlerMap
|
|
14
|
+
* @property {boolean} literal - Indicates if the expression is a literal.
|
|
15
|
+
* @property {boolean} constant - Indicates if the expression is constant.
|
|
16
|
+
* @property {boolean} [isPure]
|
|
17
|
+
* @property {boolean} oneTime
|
|
18
|
+
* @property {Map<string, Function>} keyMap - property keys to observe
|
|
19
|
+
*/
|
|
11
20
|
/**
|
|
12
21
|
* @typedef {Function} CompiledExpressionFunction
|
|
13
22
|
* @param {import('../scope/scope').Scope} context - An object against which any expressions embedded in the strings are evaluated against (typically a scope object).
|
|
@@ -61,6 +70,7 @@ export type CompiledExpressionProps = {
|
|
|
61
70
|
constant: boolean;
|
|
62
71
|
isPure?: boolean;
|
|
63
72
|
oneTime: boolean;
|
|
73
|
+
decoratedNode: import("./interpreter.js").DecoratedASTNode;
|
|
64
74
|
$$watchDelegate?: (arg0: import("../scope/scope").Scope, arg1: import("../scope/scope").WatchListener, arg2: boolean, arg3: CompiledExpression, arg4: string | ((scope: import("../scope/scope").Scope) => any) | CompiledExpression) => any;
|
|
65
75
|
inputs: any[] | Function;
|
|
66
76
|
/**
|
|
@@ -68,6 +78,22 @@ export type CompiledExpressionProps = {
|
|
|
68
78
|
*/
|
|
69
79
|
assign?: (arg0: any, arg1: any) => any;
|
|
70
80
|
};
|
|
81
|
+
export type CompiledExpressionHandlerMap = {
|
|
82
|
+
/**
|
|
83
|
+
* - Indicates if the expression is a literal.
|
|
84
|
+
*/
|
|
85
|
+
literal: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* - Indicates if the expression is constant.
|
|
88
|
+
*/
|
|
89
|
+
constant: boolean;
|
|
90
|
+
isPure?: boolean;
|
|
91
|
+
oneTime: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* - property keys to observe
|
|
94
|
+
*/
|
|
95
|
+
keyMap: Map<string, Function>;
|
|
96
|
+
};
|
|
71
97
|
export type CompiledExpressionFunction = Function;
|
|
72
98
|
export type CompiledExpression = CompiledExpressionFunction & CompiledExpressionProps;
|
|
73
99
|
export type ParseService = (arg0: CompiledExpression | string | ((arg0: import("../scope/scope").Scope) => any), arg1: ((arg0: any, arg1: import("../scope/scope").Scope, arg2: any) => any) | undefined, arg2: boolean | undefined) => CompiledExpression;
|
|
@@ -56,7 +56,7 @@ export type TTL = number;
|
|
|
56
56
|
export const TTL: TTL;
|
|
57
57
|
/** @type {AsyncQueueTask[]} */
|
|
58
58
|
export const $$asyncQueue: AsyncQueueTask[];
|
|
59
|
-
export const
|
|
59
|
+
export const $postUpdateQueue: any[];
|
|
60
60
|
/**
|
|
61
61
|
* @type {Function[]}
|
|
62
62
|
*/
|
|
@@ -158,10 +158,6 @@ export class Scope {
|
|
|
158
158
|
/** @type {number} */
|
|
159
159
|
$$watchersCount: number;
|
|
160
160
|
$$isolateBindings: any;
|
|
161
|
-
/**
|
|
162
|
-
* @type {?Scope}
|
|
163
|
-
*/
|
|
164
|
-
$$ChildScope: Scope | null;
|
|
165
161
|
/**
|
|
166
162
|
* Creates a new child {@link Scope}.
|
|
167
163
|
*
|
|
@@ -177,16 +173,21 @@ export class Scope {
|
|
|
177
173
|
* When creating widgets, it is useful for the widget to not accidentally read parent
|
|
178
174
|
* state.
|
|
179
175
|
*
|
|
180
|
-
* @param {?Scope} [parent=this] The {@link ng.$rootScope.Scope `Scope`} that will be the `$parent`
|
|
181
|
-
* of the newly created scope. Defaults to `this` scope if not provided.
|
|
182
|
-
* This is used when creating a transclude scope to correctly place it
|
|
183
|
-
* in the scope hierarchy while maintaining the correct prototypical
|
|
184
|
-
* inheritance.
|
|
185
176
|
*
|
|
186
177
|
* @returns {Scope} The newly created child scope.
|
|
187
178
|
*
|
|
188
179
|
*/
|
|
189
|
-
$new(isolate: boolean | null
|
|
180
|
+
$new(isolate: boolean | null): Scope;
|
|
181
|
+
/**
|
|
182
|
+
* Creates a transcluded scope
|
|
183
|
+
* @param {Scope} parent The {@link ng.$rootScope.Scope `Scope`} that will be the `$parent`
|
|
184
|
+
* of the newly created scope. This is used when creating a transclude scope to correctly place it
|
|
185
|
+
* in the scope hierarchy while maintaining the correct prototypical inheritance.
|
|
186
|
+
*
|
|
187
|
+
* @returns {Scope} The newly created child scope.
|
|
188
|
+
*
|
|
189
|
+
*/
|
|
190
|
+
$transcluded(parent: Scope): Scope;
|
|
190
191
|
/**
|
|
191
192
|
* Registers a `listener` callback to be executed whenever the `watchExpression` changes.
|
|
192
193
|
*
|
|
@@ -239,16 +240,16 @@ export class Scope {
|
|
|
239
240
|
});
|
|
240
241
|
expect(scope.counter).toEqual(0);
|
|
241
242
|
|
|
242
|
-
|
|
243
|
+
;
|
|
243
244
|
// the listener is always called during the first $digest loop after it was registered
|
|
244
245
|
expect(scope.counter).toEqual(1);
|
|
245
246
|
|
|
246
|
-
|
|
247
|
+
;
|
|
247
248
|
// but now it will not be called unless the value changes
|
|
248
249
|
expect(scope.counter).toEqual(1);
|
|
249
250
|
|
|
250
251
|
scope.name = 'adam';
|
|
251
|
-
|
|
252
|
+
;
|
|
252
253
|
expect(scope.counter).toEqual(2);
|
|
253
254
|
|
|
254
255
|
// Using a function as a watchExpression
|
|
@@ -270,12 +271,12 @@ export class Scope {
|
|
|
270
271
|
expect(scope.foodCounter).toEqual(0);
|
|
271
272
|
|
|
272
273
|
// Run the digest but since food has not changed count will still be zero
|
|
273
|
-
|
|
274
|
+
;
|
|
274
275
|
expect(scope.foodCounter).toEqual(0);
|
|
275
276
|
|
|
276
277
|
// Update food and run digest. Now the counter will increment
|
|
277
278
|
food = 'cheeseburger';
|
|
278
|
-
|
|
279
|
+
;
|
|
279
280
|
expect(scope.foodCounter).toEqual(1);
|
|
280
281
|
|
|
281
282
|
* ```
|
|
@@ -377,16 +378,16 @@ export class Scope {
|
|
|
377
378
|
});
|
|
378
379
|
expect(scope.counter).toEqual(0);
|
|
379
380
|
|
|
380
|
-
|
|
381
|
+
;
|
|
381
382
|
// the listener is always called during the first $digest loop after it was registered
|
|
382
383
|
expect(scope.counter).toEqual(1);
|
|
383
384
|
|
|
384
|
-
|
|
385
|
+
;
|
|
385
386
|
// but now it will not be called unless the value changes
|
|
386
387
|
expect(scope.counter).toEqual(1);
|
|
387
388
|
|
|
388
389
|
scope.name = 'adam';
|
|
389
|
-
|
|
390
|
+
;
|
|
390
391
|
expect(scope.counter).toEqual(2);
|
|
391
392
|
* ```
|
|
392
393
|
*
|
|
@@ -411,7 +412,7 @@ export class Scope {
|
|
|
411
412
|
* Some of the things to consider are:
|
|
412
413
|
*
|
|
413
414
|
* * Any external event on a directive/component will not trigger a digest while the hosting
|
|
414
|
-
* scope is suspended - even if the event handler calls `$apply()` or
|
|
415
|
+
* scope is suspended - even if the event handler calls `$apply()` or ``.
|
|
415
416
|
* * Transcluded content exists on a scope that inherits from outside a directive but exists
|
|
416
417
|
* as a child of the directive's containing scope. If the containing scope is suspended the
|
|
417
418
|
* transcluded scope will also be suspended, even if the scope from which the transcluded
|
|
@@ -614,7 +615,7 @@ export class Scope {
|
|
|
614
615
|
* @returns {*} The result of evaluating the expression.
|
|
615
616
|
*/
|
|
616
617
|
$eval(expr?: string | ((arg0: Scope) => any), locals?: (object) | undefined): any;
|
|
617
|
-
|
|
618
|
+
$postUpdate(fn: any): void;
|
|
618
619
|
/**
|
|
619
620
|
* @private
|
|
620
621
|
*/
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamically updates an element's content based on events published on a specified channel.
|
|
3
|
+
* When the directive is applied, it listens for data sent via `EventBus` and
|
|
4
|
+
* updates the inner HTML of the element accordingly.
|
|
5
|
+
*
|
|
6
|
+
* When the scope is destroyed, the directive automatically unsubscribes from the channel.
|
|
7
|
+
*
|
|
8
|
+
*
|
|
9
|
+
* @returns {import("../../types").Directive}
|
|
10
|
+
*/
|
|
11
|
+
export function ngChannelDirective(): import("../../types").Directive;
|
|
@@ -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,18 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8" />
|
|
5
|
-
<title>AngularTS Test Runner</title>
|
|
6
|
-
|
|
7
|
-
<link rel="shortcut icon" type="image/png" href="/images/favicon.ico" />
|
|
8
|
-
<link rel="stylesheet" href="/jasmine/jasmine-5.1.2/jasmine.css" />
|
|
9
|
-
<script src="/jasmine/jasmine-5.1.2/jasmine.js"></script>
|
|
10
|
-
<script src="/jasmine/jasmine-5.1.2/jasmine-html.js"></script>
|
|
11
|
-
<script src="/jasmine/jasmine-5.1.2/boot0.js"></script>
|
|
12
|
-
<script src="/jasmine/jasmine-5.1.2/boot1.js"></script>
|
|
13
|
-
<script type="module" src="/src/core/interval/interval.spec.js"></script>
|
|
14
|
-
</head>
|
|
15
|
-
<body>
|
|
16
|
-
<div id="dummy"></div>
|
|
17
|
-
</body>
|
|
18
|
-
</html>
|
|
@@ -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
|
-
\*/
|