File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -38,16 +38,21 @@ export class StateObjectDataStore implements DSRDataStore {
38
38
export class LocalStorageDataStore implements DSRDataStore {
39
39
private router : UIRouter ;
40
40
private key = 'uiRouterDeepStateRedirect' ;
41
+ private _storage : Storage = localStorage ;
42
+
43
+ constructor ( storage ?: Storage ) {
44
+ this . _storage = storage || localStorage ;
45
+ }
41
46
42
47
private getStore ( ) {
43
- const item = localStorage . getItem ( this . key ) ;
48
+ const item = this . _storage . getItem ( this . key ) ;
44
49
return JSON . parse ( item || '{}' ) ;
45
50
}
46
51
47
52
private setStore ( contents : any ) {
48
53
if ( contents ) {
49
54
try {
50
- localStorage . setItem ( this . key , JSON . stringify ( contents ) ) ;
55
+ this . _storage . setItem ( this . key , JSON . stringify ( contents ) ) ;
51
56
} catch ( err ) {
52
57
console . error (
53
58
'UI-Router Deep State Redirect: cannot store object in LocalStorage. Is there a circular reference?' ,
@@ -56,7 +61,7 @@ export class LocalStorageDataStore implements DSRDataStore {
56
61
console . error ( err ) ;
57
62
}
58
63
} else {
59
- localStorage . removeItem ( this . key ) ;
64
+ this . _storage . removeItem ( this . key ) ;
60
65
}
61
66
}
62
67
@@ -82,3 +87,9 @@ export class LocalStorageDataStore implements DSRDataStore {
82
87
this . setStore ( store ) ;
83
88
}
84
89
}
90
+
91
+ export class SessionStorageDataStore extends LocalStorageDataStore {
92
+ constructor ( ) {
93
+ super ( sessionStorage ) ;
94
+ }
95
+ }
You can’t perform that action at this time.
0 commit comments