diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-09-06 22:40:57 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-09-06 22:40:57 +0200 |
commit | ab32b0fc805b92c5a1d7ac5901cb1a38e94622ca (patch) | |
tree | 1749a7390cf0a726a179c5fa554053f5c0f0e51c /client/src/app/app.service.ts | |
parent | 088a967fe0bc285aa7811515f6a9655e1144b9f9 (diff) | |
download | PeerTube-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.ts | 36 |
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 | |||
2 | import { Injectable } from '@angular/core'; | ||
3 | |||
4 | @Injectable() | ||
5 | export 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 | } | ||