@@ -5,62 +5,68 @@ var History = require('../History');
5
5
/**
6
6
* A location that is convenient for testing and does not require a DOM.
7
7
*/
8
- function TestLocation ( history ) {
9
- this . history = history || [ ] ;
10
- this . listeners = [ ] ;
11
- this . _updateHistoryLength ( ) ;
12
- }
8
+ class TestLocation {
9
+
10
+ constructor ( history ) {
11
+ this . history = history || [ ] ;
12
+ this . listeners = [ ] ;
13
+ this . _updateHistoryLength ( ) ;
14
+ }
15
+
16
+ get needsDOM ( ) {
17
+ return false ;
18
+ }
19
+
20
+ _updateHistoryLength ( ) {
21
+ History . length = this . history . length ;
22
+ }
23
+
24
+ _notifyChange ( type ) {
25
+ for ( var i = 0 , len = this . listeners . length ; i < len ; ++ i )
26
+ this . listeners [ i ] . call ( this , { path : this . getCurrentPath ( ) , type : type } ) ;
27
+ }
28
+
29
+ addChangeListener ( listener ) {
30
+ this . listeners . push ( listener ) ;
31
+ }
32
+
33
+ removeChangeListener ( listener ) {
34
+ this . listeners = this . listeners . filter ( function ( l ) {
35
+ return l !== listener ;
36
+ } ) ;
37
+ }
38
+
39
+ push ( path ) {
40
+ this . history . push ( path ) ;
41
+ this . _updateHistoryLength ( ) ;
42
+ this . _notifyChange ( LocationActions . PUSH ) ;
43
+ }
13
44
14
- TestLocation . prototype . needsDOM = false ;
15
-
16
- TestLocation . prototype . _updateHistoryLength = function ( ) {
17
- History . length = this . history . length ;
18
- } ;
19
-
20
- TestLocation . prototype . _notifyChange = function ( type ) {
21
- for ( var i = 0 , len = this . listeners . length ; i < len ; ++ i )
22
- this . listeners [ i ] . call ( this , { path : this . getCurrentPath ( ) , type : type } ) ;
23
- } ;
24
-
25
- TestLocation . prototype . addChangeListener = function ( listener ) {
26
- this . listeners . push ( listener ) ;
27
- } ;
28
-
29
- TestLocation . prototype . removeChangeListener = function ( listener ) {
30
- this . listeners = this . listeners . filter ( function ( l ) {
31
- return l !== listener ;
32
- } ) ;
33
- } ;
34
-
35
- TestLocation . prototype . push = function ( path ) {
36
- this . history . push ( path ) ;
37
- this . _updateHistoryLength ( ) ;
38
- this . _notifyChange ( LocationActions . PUSH ) ;
39
- } ;
40
-
41
- TestLocation . prototype . replace = function ( path ) {
42
- invariant (
43
- this . history . length ,
44
- 'You cannot replace the current path with no history'
45
- ) ;
46
-
47
- this . history [ this . history . length - 1 ] = path ;
48
-
49
- this . _notifyChange ( LocationActions . REPLACE ) ;
50
- } ;
51
-
52
- TestLocation . prototype . pop = function ( ) {
53
- this . history . pop ( ) ;
54
- this . _updateHistoryLength ( ) ;
55
- this . _notifyChange ( LocationActions . POP ) ;
56
- } ;
57
-
58
- TestLocation . prototype . getCurrentPath = function ( ) {
59
- return this . history [ this . history . length - 1 ] ;
60
- } ;
61
-
62
- TestLocation . prototype . toString = function ( ) {
63
- return '<TestLocation>' ;
64
- } ;
45
+ replace ( path ) {
46
+ invariant (
47
+ this . history . length ,
48
+ 'You cannot replace the current path with no history'
49
+ ) ;
50
+
51
+ this . history [ this . history . length - 1 ] = path ;
52
+
53
+ this . _notifyChange ( LocationActions . REPLACE ) ;
54
+ }
55
+
56
+ pop ( ) {
57
+ this . history . pop ( ) ;
58
+ this . _updateHistoryLength ( ) ;
59
+ this . _notifyChange ( LocationActions . POP ) ;
60
+ }
61
+
62
+ getCurrentPath ( ) {
63
+ return this . history [ this . history . length - 1 ] ;
64
+ }
65
+
66
+ toString ( ) {
67
+ return '<TestLocation>' ;
68
+ }
69
+
70
+ }
65
71
66
72
module . exports = TestLocation ;
0 commit comments