2 import { Injectable } from '@angular/core';
5 export class AppState {
10 // already return a clone of the current state
12 return this._state = this._clone(this._state);
14 // never allow mutation
16 throw new Error('do not mutate the `.state` directly');
21 // use our state getter for the clone
22 const state = this.state;
23 return state.hasOwnProperty(prop) ? state[prop] : state;
26 set(prop: string, value: any) {
27 // internally mutate our state
28 return this._state[prop] = value;
33 // simple object clone
34 return JSON.parse(JSON.stringify( object ));