aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/app.service.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-09-06 22:40:57 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-09-06 22:40:57 +0200
commitab32b0fc805b92c5a1d7ac5901cb1a38e94622ca (patch)
tree1749a7390cf0a726a179c5fa554053f5c0f0e51c /client/src/app/app.service.ts
parent088a967fe0bc285aa7811515f6a9655e1144b9f9 (diff)
downloadPeerTube-ab32b0fc805b92c5a1d7ac5901cb1a38e94622ca.tar.gz
PeerTube-ab32b0fc805b92c5a1d7ac5901cb1a38e94622ca.tar.zst
PeerTube-ab32b0fc805b92c5a1d7ac5901cb1a38e94622ca.zip
Dirty update to Angular RC6
Diffstat (limited to 'client/src/app/app.service.ts')
-rw-r--r--client/src/app/app.service.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/client/src/app/app.service.ts b/client/src/app/app.service.ts
new file mode 100644
index 000000000..033c21900
--- /dev/null
+++ b/client/src/app/app.service.ts
@@ -0,0 +1,36 @@
1
2import { Injectable } from '@angular/core';
3
4@Injectable()
5export class AppState {
6 _state = { };
7
8 constructor() { ; }
9
10 // already return a clone of the current state
11 get state() {
12 return this._state = this._clone(this._state);
13 }
14 // never allow mutation
15 set state(value) {
16 throw new Error('do not mutate the `.state` directly');
17 }
18
19
20 get(prop?: any) {
21 // use our state getter for the clone
22 const state = this.state;
23 return state.hasOwnProperty(prop) ? state[prop] : state;
24 }
25
26 set(prop: string, value: any) {
27 // internally mutate our state
28 return this._state[prop] = value;
29 }
30
31
32 _clone(object) {
33 // simple object clone
34 return JSON.parse(JSON.stringify( object ));
35 }
36}