@angular-wave/angular.ts 0.0.65 → 0.0.67
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 +2 -2
- package/package.json +1 -1
- package/src/animations/animate-js.js +6 -0
- package/src/animations/animate-swap.js +3 -0
- package/src/animations/animation.js +1 -1
- package/src/core/compile/compile.js +16 -4
- package/src/core/controller/controller.js +5 -5
- package/src/core/di/injector.js +133 -259
- package/src/core/di/injector.md +3 -3
- package/src/core/di/injector.spec.js +30 -24
- package/src/core/di/internal-injector.js +286 -0
- package/src/core/filter/filter.js +5 -0
- package/src/core/parser/parse.js +1 -12
- package/src/core/parser/parse.spec.js +96 -110
- package/src/core/sce/sce.js +6 -1
- package/src/core/timeout/timeout.js +110 -111
- package/src/directive/input/input.js +32 -726
- package/src/directive/input/input.md +706 -0
- package/src/directive/select/select.js +48 -122
- package/src/directive/select/select.md +74 -0
- package/src/directive/show-hide/show-hide.js +13 -224
- package/src/directive/show-hide/show-hide.md +257 -0
- package/src/filters/limit-to.spec.js +1 -1
- package/src/filters/order-by.spec.js +1 -1
- package/src/index.js +6 -2
- package/src/loader.js +8 -4
- package/src/public.js +1 -7
- package/src/router/services.js +9 -4
- package/src/router/state/state-builder.js +6 -7
- package/src/router/state/state-registry.js +5 -0
- package/src/router/state/state-service.js +1 -1
- package/src/router/state/views.js +2 -1
- package/src/router/state-provider.js +1 -1
- package/src/router/template-factory.js +15 -14
- package/src/router/url/url-service.js +4 -4
- package/src/services/anchor-scroll.js +2 -2
- package/src/services/browser.js +2 -9
- package/src/services/cache-factory.js +0 -67
- package/src/services/cache-factory.md +75 -0
- package/src/services/cookie-reader.js +36 -55
- package/src/services/http/http.js +73 -586
- package/src/services/http/http.md +413 -0
- package/src/services/http-backend/http-backend.js +19 -44
- package/src/services/template-request.js +1 -9
- package/src/shared/jqlite/jqlite.js +4 -69
- package/src/types.js +8 -12
- package/types/animations/animate-js.d.ts +1 -1
- package/types/animations/animate-swap.d.ts +4 -7
- package/types/animations/animation.d.ts +1 -1
- package/types/core/compile/compile.d.ts +7 -7
- package/types/core/controller/controller.d.ts +1 -6
- package/types/core/di/injector.d.ts +13 -7
- package/types/core/di/internal-injector.d.ts +91 -0
- package/types/core/exception-handler.d.ts +1 -1
- package/types/core/filter/filter.d.ts +1 -1
- package/types/core/parser/parse.d.ts +1 -1
- package/types/core/sce/sce.d.ts +1 -1
- package/types/core/timeout/timeout.d.ts +16 -26
- package/types/directive/input/input.d.ts +19 -124
- package/types/directive/select/select.d.ts +7 -74
- package/types/directive/show-hide/show-hide.d.ts +11 -224
- package/types/loader.d.ts +4 -4
- package/types/router/services.d.ts +8 -1
- package/types/router/state/state-builder.d.ts +1 -2
- package/types/router/state/state-registry.d.ts +2 -2
- package/types/router/state/state-service.d.ts +2 -2
- package/types/router/state-provider.d.ts +2 -2
- package/types/router/template-factory.d.ts +16 -16
- package/types/router/url/url-service.d.ts +4 -4
- package/types/services/anchor-scroll.d.ts +1 -1
- package/types/services/browser.d.ts +0 -10
- package/types/services/cache-factory.d.ts +0 -67
- package/types/services/cookie-reader.d.ts +2 -10
- package/types/services/http/http.d.ts +53 -61
- package/types/services/http-backend/http-backend.d.ts +8 -31
- package/types/services/template-request.d.ts +1 -9
- package/types/shared/jqlite/jqlite.d.ts +9 -9
- package/types/types.d.ts +5 -38
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AST } from "./ast";
|
|
2
2
|
import { Lexer } from "./lexer";
|
|
3
3
|
import {
|
|
4
|
-
forEach,
|
|
5
4
|
isFunction,
|
|
6
5
|
sliceArgs,
|
|
7
6
|
csp,
|
|
@@ -580,27 +579,24 @@ describe("parser", () => {
|
|
|
580
579
|
|
|
581
580
|
it("should understand literals", () => {
|
|
582
581
|
// In a strict sense, `undefined` is not a literal but an identifier
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
{
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
});
|
|
602
|
-
},
|
|
603
|
-
);
|
|
582
|
+
Object.entries({
|
|
583
|
+
123: 123,
|
|
584
|
+
'"123"': "123",
|
|
585
|
+
true: true,
|
|
586
|
+
false: false,
|
|
587
|
+
null: null,
|
|
588
|
+
undefined: undefined,
|
|
589
|
+
}).forEach(([expression, value]) => {
|
|
590
|
+
expect(createAst(expression)).toEqual({
|
|
591
|
+
type: ASTType.Program,
|
|
592
|
+
body: [
|
|
593
|
+
{
|
|
594
|
+
type: ASTType.ExpressionStatement,
|
|
595
|
+
expression: { type: ASTType.Literal, value },
|
|
596
|
+
},
|
|
597
|
+
],
|
|
598
|
+
});
|
|
599
|
+
});
|
|
604
600
|
});
|
|
605
601
|
|
|
606
602
|
it("should understand the `this` expression", () => {
|
|
@@ -628,8 +624,7 @@ describe("parser", () => {
|
|
|
628
624
|
});
|
|
629
625
|
|
|
630
626
|
it("should not confuse `this`, `$locals`, `undefined`, `true`, `false`, `null` when used as identifiers", () => {
|
|
631
|
-
forEach(
|
|
632
|
-
["this", "$locals", "undefined", "true", "false", "null"],
|
|
627
|
+
["this", "$locals", "undefined", "true", "false", "null"].forEach(
|
|
633
628
|
(identifier) => {
|
|
634
629
|
expect(createAst(`foo.${identifier}`)).toEqual({
|
|
635
630
|
type: ASTType.Program,
|
|
@@ -662,7 +657,7 @@ describe("parser", () => {
|
|
|
662
657
|
});
|
|
663
658
|
|
|
664
659
|
it("should understand the unary operators `-`, `+` and `!`", () => {
|
|
665
|
-
|
|
660
|
+
["-", "+", "!"].forEach((operator) => {
|
|
666
661
|
expect(createAst(`${operator}foo`)).toEqual({
|
|
667
662
|
type: ASTType.Program,
|
|
668
663
|
body: [
|
|
@@ -681,75 +676,69 @@ describe("parser", () => {
|
|
|
681
676
|
});
|
|
682
677
|
|
|
683
678
|
it("should handle all unary operators with the same precedence", () => {
|
|
684
|
-
|
|
685
|
-
[
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
{
|
|
695
|
-
type: ASTType.
|
|
696
|
-
|
|
679
|
+
[
|
|
680
|
+
["+", "-", "!"],
|
|
681
|
+
["-", "!", "+"],
|
|
682
|
+
["!", "+", "-"],
|
|
683
|
+
].forEach((operators) => {
|
|
684
|
+
expect(createAst(`${operators.join("")}foo`)).toEqual({
|
|
685
|
+
type: ASTType.Program,
|
|
686
|
+
body: [
|
|
687
|
+
{
|
|
688
|
+
type: ASTType.ExpressionStatement,
|
|
689
|
+
expression: {
|
|
690
|
+
type: ASTType.UnaryExpression,
|
|
691
|
+
operator: operators[0],
|
|
692
|
+
prefix: true,
|
|
693
|
+
argument: {
|
|
697
694
|
type: ASTType.UnaryExpression,
|
|
698
|
-
operator: operators[
|
|
695
|
+
operator: operators[1],
|
|
699
696
|
prefix: true,
|
|
700
697
|
argument: {
|
|
701
698
|
type: ASTType.UnaryExpression,
|
|
702
|
-
operator: operators[
|
|
699
|
+
operator: operators[2],
|
|
703
700
|
prefix: true,
|
|
704
|
-
argument: {
|
|
705
|
-
type: ASTType.UnaryExpression,
|
|
706
|
-
operator: operators[2],
|
|
707
|
-
prefix: true,
|
|
708
|
-
argument: { type: ASTType.Identifier, name: "foo" },
|
|
709
|
-
},
|
|
701
|
+
argument: { type: ASTType.Identifier, name: "foo" },
|
|
710
702
|
},
|
|
711
703
|
},
|
|
712
704
|
},
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
}
|
|
716
|
-
);
|
|
705
|
+
},
|
|
706
|
+
],
|
|
707
|
+
});
|
|
708
|
+
});
|
|
717
709
|
});
|
|
718
710
|
|
|
719
711
|
it("should be able to understand binary operators", () => {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
{
|
|
741
|
-
type: ASTType.
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
left: { type: ASTType.Identifier, name: "foo" },
|
|
746
|
-
right: { type: ASTType.Identifier, name: "bar" },
|
|
747
|
-
},
|
|
712
|
+
[
|
|
713
|
+
"*",
|
|
714
|
+
"/",
|
|
715
|
+
"%",
|
|
716
|
+
"+",
|
|
717
|
+
"-",
|
|
718
|
+
"<",
|
|
719
|
+
">",
|
|
720
|
+
"<=",
|
|
721
|
+
">=",
|
|
722
|
+
"==",
|
|
723
|
+
"!=",
|
|
724
|
+
"===",
|
|
725
|
+
"!==",
|
|
726
|
+
].forEach((operator) => {
|
|
727
|
+
expect(createAst(`foo${operator}bar`)).toEqual({
|
|
728
|
+
type: ASTType.Program,
|
|
729
|
+
body: [
|
|
730
|
+
{
|
|
731
|
+
type: ASTType.ExpressionStatement,
|
|
732
|
+
expression: {
|
|
733
|
+
type: ASTType.BinaryExpression,
|
|
734
|
+
operator,
|
|
735
|
+
left: { type: ASTType.Identifier, name: "foo" },
|
|
736
|
+
right: { type: ASTType.Identifier, name: "bar" },
|
|
748
737
|
},
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
}
|
|
752
|
-
);
|
|
738
|
+
},
|
|
739
|
+
],
|
|
740
|
+
});
|
|
741
|
+
});
|
|
753
742
|
});
|
|
754
743
|
|
|
755
744
|
it("should associate binary operators with the same precedence left-to-right", () => {
|
|
@@ -759,9 +748,9 @@ describe("parser", () => {
|
|
|
759
748
|
["<", ">", "<=", ">="],
|
|
760
749
|
["==", "!=", "===", "!=="],
|
|
761
750
|
];
|
|
762
|
-
forEach(
|
|
763
|
-
forEach(
|
|
764
|
-
forEach(
|
|
751
|
+
operatorsByPrecedence.forEach((operators) => {
|
|
752
|
+
operators.forEach((op1) => {
|
|
753
|
+
operators.forEach((op2) => {
|
|
765
754
|
expect(createAst(`foo${op1}bar${op2}baz`)).toEqual({
|
|
766
755
|
type: ASTType.Program,
|
|
767
756
|
body: [
|
|
@@ -787,7 +776,7 @@ describe("parser", () => {
|
|
|
787
776
|
});
|
|
788
777
|
|
|
789
778
|
it("should give higher precedence to member calls than to unary expressions", () => {
|
|
790
|
-
|
|
779
|
+
["!", "+", "-"].forEach((operator) => {
|
|
791
780
|
expect(createAst(`${operator}foo()`)).toEqual({
|
|
792
781
|
type: ASTType.Program,
|
|
793
782
|
body: [
|
|
@@ -848,8 +837,8 @@ describe("parser", () => {
|
|
|
848
837
|
});
|
|
849
838
|
|
|
850
839
|
it("should give higher precedence to unary operators over multiplicative operators", () => {
|
|
851
|
-
|
|
852
|
-
|
|
840
|
+
["!", "+", "-"].forEach((op1) => {
|
|
841
|
+
["*", "/", "%"].forEach((op2) => {
|
|
853
842
|
expect(createAst(`${op1}foo${op2}${op1}bar`)).toEqual({
|
|
854
843
|
type: ASTType.Program,
|
|
855
844
|
body: [
|
|
@@ -886,8 +875,8 @@ describe("parser", () => {
|
|
|
886
875
|
["==", "!=", "===", "!=="],
|
|
887
876
|
];
|
|
888
877
|
for (let i = 0; i < operatorsByPrecedence.length - 1; ++i) {
|
|
889
|
-
|
|
890
|
-
|
|
878
|
+
operatorsByPrecedence[i].forEach((op1) => {
|
|
879
|
+
operatorsByPrecedence[i + 1].forEach((op2) => {
|
|
891
880
|
expect(createAst(`foo${op1}bar${op2}baz${op1}man`)).toEqual({
|
|
892
881
|
type: ASTType.Program,
|
|
893
882
|
body: [
|
|
@@ -918,7 +907,7 @@ describe("parser", () => {
|
|
|
918
907
|
});
|
|
919
908
|
|
|
920
909
|
it("should understand logical operators", () => {
|
|
921
|
-
|
|
910
|
+
["||", "&&"].forEach((operator) => {
|
|
922
911
|
expect(createAst(`foo${operator}bar`)).toEqual({
|
|
923
912
|
type: ASTType.Program,
|
|
924
913
|
body: [
|
|
@@ -937,7 +926,7 @@ describe("parser", () => {
|
|
|
937
926
|
});
|
|
938
927
|
|
|
939
928
|
it("should associate logical operators left-to-right", () => {
|
|
940
|
-
|
|
929
|
+
["||", "&&"].forEach((op) => {
|
|
941
930
|
expect(createAst(`foo${op}bar${op}baz`)).toEqual({
|
|
942
931
|
type: ASTType.Program,
|
|
943
932
|
body: [
|
|
@@ -1053,7 +1042,7 @@ describe("parser", () => {
|
|
|
1053
1042
|
});
|
|
1054
1043
|
|
|
1055
1044
|
it("should give higher precedence to equality than to the logical `and` operator", () => {
|
|
1056
|
-
|
|
1045
|
+
["==", "!=", "===", "!=="].forEach((operator) => {
|
|
1057
1046
|
expect(createAst(`foo${operator}bar && man${operator}shell`)).toEqual({
|
|
1058
1047
|
type: ASTType.Program,
|
|
1059
1048
|
body: [
|
|
@@ -1775,7 +1764,7 @@ describe("parser", () => {
|
|
|
1775
1764
|
});
|
|
1776
1765
|
});
|
|
1777
1766
|
|
|
1778
|
-
|
|
1767
|
+
[true, false].forEach((cspEnabled) => {
|
|
1779
1768
|
describe(`csp: ${cspEnabled}`, () => {
|
|
1780
1769
|
beforeEach(() => {
|
|
1781
1770
|
createInjector([
|
|
@@ -2016,7 +2005,7 @@ describe("parser", () => {
|
|
|
2016
2005
|
expect(scope.$eval("a.b.c.d.e.f.g.h.i.j.k.l.m.n", scope)).toBe("nooo!");
|
|
2017
2006
|
});
|
|
2018
2007
|
|
|
2019
|
-
|
|
2008
|
+
[2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 42, 99].forEach((pathLength) => {
|
|
2020
2009
|
it(`should resolve nested paths of length ${pathLength}`, () => {
|
|
2021
2010
|
// Create a nested object {x2: {x3: {x4: ... {x[n]: 42} ... }}}.
|
|
2022
2011
|
let obj = 42;
|
|
@@ -2397,23 +2386,20 @@ describe("parser", () => {
|
|
|
2397
2386
|
|
|
2398
2387
|
it("should throw TypeError on using a 'broken' object as a key to access a property", () => {
|
|
2399
2388
|
scope.object = {};
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
{
|
|
2405
|
-
|
|
2406
|
-
return {};
|
|
2407
|
-
},
|
|
2389
|
+
[
|
|
2390
|
+
{ toString: 2 },
|
|
2391
|
+
{ toString: null },
|
|
2392
|
+
{
|
|
2393
|
+
toString() {
|
|
2394
|
+
return {};
|
|
2408
2395
|
},
|
|
2409
|
-
],
|
|
2410
|
-
(brokenObject) => {
|
|
2411
|
-
scope.brokenObject = brokenObject;
|
|
2412
|
-
expect(() => {
|
|
2413
|
-
scope.$eval("object[brokenObject]");
|
|
2414
|
-
}).toThrow();
|
|
2415
2396
|
},
|
|
2416
|
-
)
|
|
2397
|
+
].forEach((brokenObject) => {
|
|
2398
|
+
scope.brokenObject = brokenObject;
|
|
2399
|
+
expect(() => {
|
|
2400
|
+
scope.$eval("object[brokenObject]");
|
|
2401
|
+
}).toThrow();
|
|
2402
|
+
});
|
|
2417
2403
|
});
|
|
2418
2404
|
|
|
2419
2405
|
it("should support method calls on primitive types", () => {
|
package/src/core/sce/sce.js
CHANGED
|
@@ -248,7 +248,12 @@ export function $SceDelegateProvider() {
|
|
|
248
248
|
this.$get = [
|
|
249
249
|
"$injector",
|
|
250
250
|
"$$sanitizeUri",
|
|
251
|
-
|
|
251
|
+
/**
|
|
252
|
+
*
|
|
253
|
+
* @param {import("../../core/di/internal-injector").InjectorService} $injector
|
|
254
|
+
* @param {*} $$sanitizeUri
|
|
255
|
+
* @returns
|
|
256
|
+
*/
|
|
252
257
|
function ($injector, $$sanitizeUri) {
|
|
253
258
|
let htmlSanitizer = function () {
|
|
254
259
|
throw $sceMinErr(
|
|
@@ -3,128 +3,127 @@ import { isDefined, isFunction, minErr, sliceArgs } from "../../shared/utils";
|
|
|
3
3
|
|
|
4
4
|
const $timeoutMinErr = minErr("$timeout");
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* block and delegates any exceptions to
|
|
25
|
-
* {@link ng.$exceptionHandler $exceptionHandler} service.
|
|
26
|
-
*
|
|
27
|
-
* The return value of calling `$timeout` is a promise, which will be resolved when
|
|
28
|
-
* the delay has passed and the timeout function, if provided, is executed.
|
|
29
|
-
*
|
|
30
|
-
* To cancel a timeout request, call `$timeout.cancel(promise)`.
|
|
31
|
-
*
|
|
32
|
-
* In tests you can use {@link ngMock.$timeout `$timeout.flush()`} to
|
|
33
|
-
* synchronously flush the queue of deferred functions.
|
|
34
|
-
*
|
|
35
|
-
* If you only want a promise that will be resolved after some specified delay
|
|
36
|
-
* then you can call `$timeout` without the `fn` function.
|
|
37
|
-
*
|
|
38
|
-
* @param {function()=} fn A function, whose execution should be delayed.
|
|
39
|
-
* @param {number=} [delay=0] Delay in milliseconds.
|
|
40
|
-
* @param {boolean=} [invokeApply=true] If set to `false` skips model dirty checking, otherwise
|
|
41
|
-
* will invoke `fn` within the {@link ng.$rootScope.Scope#$apply $apply} block.
|
|
42
|
-
* @param {...*=} Pass additional parameters to the executed function.
|
|
43
|
-
* @returns {Promise} Promise that will be resolved when the timeout is reached. The promise
|
|
44
|
-
* will be resolved with the return value of the `fn` function.
|
|
45
|
-
*
|
|
46
|
-
*/
|
|
47
|
-
function timeout(fn, delay, invokeApply) {
|
|
48
|
-
if (!isFunction(fn)) {
|
|
49
|
-
invokeApply = delay;
|
|
50
|
-
delay = fn;
|
|
51
|
-
fn = () => {};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const args = sliceArgs(arguments, 3);
|
|
55
|
-
const skipApply = isDefined(invokeApply) && !invokeApply;
|
|
56
|
-
const deferred = (skipApply ? $$q : $q).defer();
|
|
57
|
-
const { promise } = deferred;
|
|
58
|
-
let timeoutId;
|
|
6
|
+
export function $TimeoutProvider() {
|
|
7
|
+
this.$get = [
|
|
8
|
+
"$rootScope",
|
|
9
|
+
"$browser",
|
|
10
|
+
"$q",
|
|
11
|
+
"$$q",
|
|
12
|
+
"$exceptionHandler",
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param {import('../scope/scope').Scope} $rootScope
|
|
16
|
+
* @param {import('../../services/browser').Browser} $browser
|
|
17
|
+
* @param {*} $q
|
|
18
|
+
* @param {*} $$q
|
|
19
|
+
* @param {import('../exception-handler').ErrorHandler} $exceptionHandler
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
function ($rootScope, $browser, $q, $$q, $exceptionHandler) {
|
|
23
|
+
const deferreds = {};
|
|
59
24
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
25
|
+
/**
|
|
26
|
+
* @ngdoc service
|
|
27
|
+
* @name $timeout
|
|
28
|
+
*
|
|
29
|
+
* @description
|
|
30
|
+
* AngularJS's wrapper for `window.setTimeout`. The `fn` function is wrapped into a try/catch
|
|
31
|
+
* block and delegates any exceptions to
|
|
32
|
+
* {@link ng.$exceptionHandler $exceptionHandler} service.
|
|
33
|
+
*
|
|
34
|
+
* The return value of calling `$timeout` is a promise, which will be resolved when
|
|
35
|
+
* the delay has passed and the timeout function, if provided, is executed.
|
|
36
|
+
*
|
|
37
|
+
* To cancel a timeout request, call `$timeout.cancel(promise)`.
|
|
38
|
+
*
|
|
39
|
+
* In tests you can use {@link ngMock.$timeout `$timeout.flush()`} to
|
|
40
|
+
* synchronously flush the queue of deferred functions.
|
|
41
|
+
*
|
|
42
|
+
* If you only want a promise that will be resolved after some specified delay
|
|
43
|
+
* then you can call `$timeout` without the `fn` function.
|
|
44
|
+
*
|
|
45
|
+
* @param {function()=} fn A function, whose execution should be delayed.
|
|
46
|
+
* @param {number=} [delay=0] Delay in milliseconds.
|
|
47
|
+
* @param {boolean=} [invokeApply=true] If set to `false` skips model dirty checking, otherwise
|
|
48
|
+
* will invoke `fn` within the {@link ng.$rootScope.Scope#$apply $apply} block.
|
|
49
|
+
* @returns {Promise} Promise that will be resolved when the timeout is reached. The promise
|
|
50
|
+
* will be resolved with the return value of the `fn` function.
|
|
51
|
+
*
|
|
52
|
+
*/
|
|
53
|
+
function timeout(fn, delay, invokeApply = true) {
|
|
54
|
+
if (!isFunction(fn)) {
|
|
55
|
+
invokeApply = delay;
|
|
56
|
+
delay = fn;
|
|
57
|
+
fn = () => {};
|
|
69
58
|
}
|
|
70
59
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
60
|
+
const args = sliceArgs(arguments, 3);
|
|
61
|
+
const skipApply = isDefined(invokeApply) && !invokeApply;
|
|
62
|
+
const deferred = (skipApply ? $$q : $q).defer();
|
|
63
|
+
const { promise } = deferred;
|
|
64
|
+
let timeoutId;
|
|
76
65
|
|
|
77
|
-
|
|
78
|
-
|
|
66
|
+
timeoutId = $browser.defer(
|
|
67
|
+
() => {
|
|
68
|
+
try {
|
|
69
|
+
deferred.resolve(fn.apply(null, args));
|
|
70
|
+
} catch (e) {
|
|
71
|
+
deferred.reject(e);
|
|
72
|
+
$exceptionHandler(e);
|
|
73
|
+
} finally {
|
|
74
|
+
delete deferreds[promise.$$timeoutId];
|
|
75
|
+
}
|
|
79
76
|
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
if (!skipApply) $rootScope.$apply();
|
|
78
|
+
},
|
|
79
|
+
delay,
|
|
80
|
+
"$timeout",
|
|
81
|
+
);
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
* @name $timeout#cancel
|
|
86
|
-
*
|
|
87
|
-
* @description
|
|
88
|
-
* Cancels a task associated with the `promise`. As a result of this, the promise will be
|
|
89
|
-
* resolved with a rejection.
|
|
90
|
-
*
|
|
91
|
-
* @param {Promise=} promise Promise returned by the `$timeout` function.
|
|
92
|
-
* @returns {boolean} Returns `true` if the task hasn't executed yet and was successfully
|
|
93
|
-
* canceled.
|
|
94
|
-
*/
|
|
95
|
-
timeout.cancel = function (promise) {
|
|
96
|
-
if (!promise) return false;
|
|
83
|
+
promise.$$timeoutId = timeoutId;
|
|
84
|
+
deferreds[timeoutId] = deferred;
|
|
97
85
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
"badprom",
|
|
101
|
-
"`$timeout.cancel()` called with a promise that was not generated by `$timeout()`.",
|
|
102
|
-
);
|
|
103
|
-
}
|
|
86
|
+
return promise;
|
|
87
|
+
}
|
|
104
88
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
89
|
+
/**
|
|
90
|
+
* @ngdoc method
|
|
91
|
+
* @name $timeout#cancel
|
|
92
|
+
*
|
|
93
|
+
* @description
|
|
94
|
+
* Cancels a task associated with the `promise`. As a result of this, the promise will be
|
|
95
|
+
* resolved with a rejection.
|
|
96
|
+
*
|
|
97
|
+
* @param {Promise=} promise Promise returned by the `$timeout` function.
|
|
98
|
+
* @returns {boolean} Returns `true` if the task hasn't executed yet and was successfully
|
|
99
|
+
* canceled.
|
|
100
|
+
*/
|
|
101
|
+
timeout.cancel = function (promise) {
|
|
102
|
+
if (!promise) return false;
|
|
109
103
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
104
|
+
if (!Object.prototype.hasOwnProperty.call(promise, "$$timeoutId")) {
|
|
105
|
+
throw $timeoutMinErr(
|
|
106
|
+
"badprom",
|
|
107
|
+
"`$timeout.cancel()` called with a promise that was not generated by `$timeout()`.",
|
|
108
|
+
);
|
|
109
|
+
}
|
|
114
110
|
|
|
115
|
-
|
|
116
|
-
|
|
111
|
+
if (
|
|
112
|
+
!Object.prototype.hasOwnProperty.call(deferreds, promise.$$timeoutId)
|
|
113
|
+
)
|
|
114
|
+
return false;
|
|
115
|
+
const id = promise.$$timeoutId;
|
|
116
|
+
const deferred = deferreds[id];
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
// Timeout cancels should not report an unhandled promise.
|
|
119
|
+
markQExceptionHandled(deferred.promise);
|
|
120
|
+
deferred.reject("canceled");
|
|
121
|
+
delete deferreds[id];
|
|
120
122
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
"$$q",
|
|
127
|
-
"$exceptionHandler",
|
|
128
|
-
$timeout,
|
|
123
|
+
return $browser.cancel(id);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return timeout;
|
|
127
|
+
},
|
|
129
128
|
];
|
|
130
129
|
}
|