import * as Proxy from "harmony-proxy";

export function createProxy ( state, previousState, multiplier ): any {
  return new Proxy( state, createHandler( previousState, multiplier ) );
}

function createHandler ( previousState, multiplier ) {
  return {
    get ( state, property ) {
      let currentValue = state[ property ]
      let previousValue = previousState[ property ]

      if ( typeof( currentValue ) === "undefined" ) {
        currentValue = previousValue
      }

      if ( typeof( previousValue ) === "undefined" ) {
        previousValue = currentValue
      }

      if ( typeof( currentValue ) === "number" && typeof( previousValue ) === "number" ) {
        let result = currentValue + ( previousValue - currentValue ) * multiplier
        return isNaN( result ) ? null : result

      } else if ( currentValue === null ) {
        return null

      } else if ( typeof( currentValue ) === "object" ) {
        return createProxy( currentValue, previousValue, multiplier )

      } else {
        return currentValue

      }
    }
  };
}

import * as Proxy from "harmony-proxy";

export function createProxy ( state, previousState, multiplier ): any {
  return new Proxy( state, createHandler( previousState, multiplier ) );
}

function createHandler ( previousState, multiplier ) {
  return {
    get ( state, property ) {
      let currentValue = state[ property ]
      let previousValue = previousState[ property ]

      if ( currentValue === undefined ) {
        currentValue = previousValue
      }

      if ( previousValue === undefined ) {
        previousValue = currentValue
      }

      if ( typeof( currentValue ) === "number" && typeof( previousValue ) === "number" ) {
        let result = currentValue + ( previousValue - currentValue ) * multiplier
        return isNaN( result ) ? null : result

      } else if ( currentValue === null ) {
        return null

      } else if ( typeof( currentValue ) === "object" ) {
        return createProxy( currentValue, previousValue, multiplier )

      } else {
        return currentValue
      }
    }
  };
}

Remove typeof in favor of strict check.
Remove typeof in favor of strict check. 

They are equivalent, there is no reason to use typeof when you can just check with an ===