import { Injectable } from '@angular/core';

export type InternalStateType = {
  [key: string]: any
};

@Injectable()
export class AppState {
  _state: InternalStateType = {};

  constructor() {
  }

  // already return a clone of the current state
  get state() {
    return this._state = this._clone(this._state);
  }

  // never allow mutation
  set state(value) {
    throw new Error('do not mutate the `.state` directly');
  }

  get(prop?: string) {
    // use our state getter for the clone
    const state = this.state;
    return state[prop];
  }

  set(prop: string, value: any) {
    // internally mutate our state
    // return this._state[prop] = value;
    this._state[prop] = value;
    console.log(this._state);
    return this._state[prop];
  }

  private _clone(object: InternalStateType) {
    // simple object clone
    return JSON.parse(JSON.stringify(object));
  }
}

import { Injectable } from '@angular/core';

export type InternalStateType = {
  [key: string]: any
};

@Injectable()
export class AppState {
  _state: InternalStateType = {};

  constructor() {
  }

  // already return a clone of the current state
  get state() {
    return this._state = this._clone(this._state);
  }

  // never allow mutation
  set state(value) {
    throw new Error('do not mutate the `.state` directly');
  }

  get(prop?: string) {
    // use our state getter for the clone
    const state = this.state;
    return state[prop];
  }

  set(prop: string, value: any) {
    // internally mutate our state
    return this._state[prop] = value;
  }

  private _clone(object: InternalStateType) {
    // simple object clone
    return JSON.parse(JSON.stringify(object));
  }
}

--- 
+++ 
@@ -29,7 +29,10 @@
 
   set(prop: string, value: any) {
     // internally mutate our state
-    return this._state[prop] = value;
+    // return this._state[prop] = value;
+    this._state[prop] = value;
+    console.log(this._state);
+    return this._state[prop];
   }
 
   private _clone(object: InternalStateType) {
Add just a log for every state change temporally
