aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/wrappers/storage.service.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-06-23 14:10:17 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-06-23 16:00:49 +0200
commit67ed6552b831df66713bac9e672738796128d33f (patch)
tree59c97d41e0b49d75a90aa3de987968ab9b1ff447 /client/src/app/core/wrappers/storage.service.ts
parent0c4bacbff53bc732f5a2677d62a6ead7752e2405 (diff)
downloadPeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.gz
PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.zst
PeerTube-67ed6552b831df66713bac9e672738796128d33f.zip
Reorganize client shared modules
Diffstat (limited to 'client/src/app/core/wrappers/storage.service.ts')
-rw-r--r--client/src/app/core/wrappers/storage.service.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/client/src/app/core/wrappers/storage.service.ts b/client/src/app/core/wrappers/storage.service.ts
new file mode 100644
index 000000000..9a60b9785
--- /dev/null
+++ b/client/src/app/core/wrappers/storage.service.ts
@@ -0,0 +1,37 @@
1import { Observable, Subject } from 'rxjs'
2import { filter } from 'rxjs/operators'
3import { Injectable } from '@angular/core'
4import { peertubeLocalStorage, peertubeSessionStorage } from '@app/helpers'
5
6abstract class StorageService {
7 protected instance: Storage
8 static storageSub = new Subject<string>()
9
10 watch (keys?: string[]): Observable<string> {
11 return StorageService.storageSub.asObservable().pipe(filter(val => keys ? keys.includes(val) : true))
12 }
13
14 getItem (key: string) {
15 return this.instance.getItem(key)
16 }
17
18 setItem (key: string, data: any, notifyOfUpdate = true) {
19 this.instance.setItem(key, data)
20 if (notifyOfUpdate) StorageService.storageSub.next(key)
21 }
22
23 removeItem (key: string, notifyOfUpdate = true) {
24 this.instance.removeItem(key)
25 if (notifyOfUpdate) StorageService.storageSub.next(key)
26 }
27}
28
29@Injectable()
30export class LocalStorageService extends StorageService {
31 protected instance: Storage = peertubeLocalStorage
32}
33
34@Injectable()
35export class SessionStorageService extends StorageService {
36 protected instance: Storage = peertubeSessionStorage
37}