Skip to main content

Command Palette

Search for a command to run...

Effect, change of state

Updated
1 min read
Effect, change of state

State change is a secondary effect generated by executing a unit of code.

To validate the result we must access the state that has changed, so it is compromised of three steps:

  • Execute the unit of code
  • Access the changed state
  • Verify the value is as expected
/** State that is changed */
let currentValue = 0;

/** Unit of code that has an effect.
 * It changes currentValue
 */
function add(summand: number): void {
  /**
   * Exit point => Effect, Change of state
   */
  currentValue += summand;
}

/**
 * Way to access current state
 */
function getCurrentValue(): number {
  return currentValue;
}

/** Execute unit of code */
sumar(5);

/** Access changed state */
const valorAcumulado = obtenerValorActual();
/** Verify obtained value is what we expect */
valorAcumulado === 5;

🇨🇴 Versión en Español