This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +46
-11
lines changed Expand file tree Collapse file tree 3 files changed +46
-11
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
2
* See example/counting.html
3
3
*/
4
- zone . countingZone = {
4
+ Zone . countingZone = {
5
5
'-onZoneCreated' : function ( ) {
6
- zone . countingZone . counter += 1 ;
6
+ Zone . countingZone . counter += 1 ;
7
7
} ,
8
8
'+onZoneLeave' : function ( ) {
9
- zone . countingZone . counter -= 1 ;
10
- if ( zone . countingZone . counter === 0 ) {
9
+ Zone . countingZone . counter -= 1 ;
10
+ if ( Zone . countingZone . counter <= 0 ) {
11
+ Zone . countingZone . counter = 0 ;
11
12
this . onFlush ( ) ;
12
13
}
13
14
} ,
14
- reset : function ( ) {
15
- zone . countingZone . counter = 0 ;
15
+ '-run' : function ( ) {
16
+ Zone . countingZone . counter = 0 ;
16
17
} ,
17
18
counter : function ( ) {
18
- return zone . countingZone . counter ;
19
+ return Zone . countingZone . counter ;
19
20
} ,
20
21
onFlush : function ( ) { }
21
22
} ;
Original file line number Diff line number Diff line change @@ -26,22 +26,22 @@ <h1>Counting Pending Tasks</h1>
26
26
/*
27
27
* Zone that counts pending async tasks
28
28
*/
29
- var myCountingZone = zone . fork ( zone . countingZone ) . fork ( {
29
+ var myCountingZone = zone . fork ( Zone . countingZone ) . fork ( {
30
30
'+onZoneCreated' : function ( ) {
31
- zone . countingZone . start || ( zone . countingZone . start = Date . now ( ) ) ;
31
+ Zone . countingZone . start || ( Zone . countingZone . start = Date . now ( ) ) ;
32
32
this . print ( ) ;
33
33
} ,
34
34
'-onZoneLeave' : function ( delegate ) {
35
35
this . print ( ) ;
36
36
} ,
37
37
'+reset' : function ( delegate ) {
38
- zone . countingZone . start = 0 ;
38
+ Zone . countingZone . start = 0 ;
39
39
} ,
40
40
print : function ( ) {
41
41
counter = this . counter ( ) ;
42
42
output . innerHTML = counter ?
43
43
'pending task count: ' + counter :
44
- ' DONE! ' + ( Date . now ( ) - zone . countingZone . start ) / 1000 + 's' ;
44
+ ' DONE! ' + ( Date . now ( ) - Zone . countingZone . start ) / 1000 + 's' ;
45
45
}
46
46
} ) ;
47
47
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+
4
+ describe ( 'Zone.countingZone' , function ( ) {
5
+ var flushSpy = jasmine . createSpy ( 'flush' ) ,
6
+ countingZone = zone . fork ( Zone . countingZone ) . fork ( {
7
+ onFlush : flushSpy
8
+ } ) ;
9
+
10
+ beforeEach ( function ( ) {
11
+ jasmine . Clock . useMock ( ) ;
12
+ flushSpy . reset ( ) ;
13
+ } ) ;
14
+
15
+ it ( 'should flush at the end of a run' , function ( ) {
16
+ countingZone . run ( function ( ) { } ) ;
17
+ expect ( flushSpy ) . toHaveBeenCalled ( ) ;
18
+ expect ( countingZone . counter ( ) ) . toBe ( 0 ) ;
19
+ } ) ;
20
+
21
+ it ( 'should work' , function ( ) {
22
+ countingZone . run ( function ( ) {
23
+
24
+ setTimeout ( function ( ) { } , 0 ) ;
25
+ expect ( countingZone . counter ( ) ) . toBe ( 1 ) ;
26
+
27
+ //jasmine.Clock.tick(0);
28
+
29
+ //expect(countingZone.counter()).toBe(0);
30
+ } ) ;
31
+
32
+ //jasmine.Clock.tick(0);
33
+ } ) ;
34
+ } ) ;
You can’t perform that action at this time.
0 commit comments