diff options
Diffstat (limited to 'client/src/app/app.service.ts')
-rw-r--r-- | client/src/app/app.service.ts | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/client/src/app/app.service.ts b/client/src/app/app.service.ts index 9b582e472..a7eb880a4 100644 --- a/client/src/app/app.service.ts +++ b/client/src/app/app.service.ts | |||
@@ -9,28 +9,38 @@ export class AppState { | |||
9 | 9 | ||
10 | public _state: InternalStateType = { }; | 10 | public _state: InternalStateType = { }; |
11 | 11 | ||
12 | // already return a clone of the current state | 12 | /** |
13 | * Already return a clone of the current state. | ||
14 | */ | ||
13 | public get state() { | 15 | public get state() { |
14 | return this._state = this._clone(this._state); | 16 | return this._state = this._clone(this._state); |
15 | } | 17 | } |
16 | // never allow mutation | 18 | /** |
19 | * Never allow mutation | ||
20 | */ | ||
17 | public set state(value) { | 21 | public set state(value) { |
18 | throw new Error('do not mutate the `.state` directly'); | 22 | throw new Error('do not mutate the `.state` directly'); |
19 | } | 23 | } |
20 | 24 | ||
21 | public get(prop?: any) { | 25 | public get(prop?: any) { |
22 | // use our state getter for the clone | 26 | /** |
27 | * Use our state getter for the clone. | ||
28 | */ | ||
23 | const state = this.state; | 29 | const state = this.state; |
24 | return state.hasOwnProperty(prop) ? state[prop] : state; | 30 | return state.hasOwnProperty(prop) ? state[prop] : state; |
25 | } | 31 | } |
26 | 32 | ||
27 | public set(prop: string, value: any) { | 33 | public set(prop: string, value: any) { |
28 | // internally mutate our state | 34 | /** |
35 | * Internally mutate our state. | ||
36 | */ | ||
29 | return this._state[prop] = value; | 37 | return this._state[prop] = value; |
30 | } | 38 | } |
31 | 39 | ||
32 | private _clone(object: InternalStateType) { | 40 | private _clone(object: InternalStateType) { |
33 | // simple object clone | 41 | /** |
42 | * Simple object clone. | ||
43 | */ | ||
34 | return JSON.parse(JSON.stringify( object )); | 44 | return JSON.parse(JSON.stringify( object )); |
35 | } | 45 | } |
36 | } | 46 | } |