getValue method

  1. @mustCallSuper
Output getValue([
  1. ValuableContext? context = const ValuableContext()
])

Get the current value of the Valuable

Implementation

@mustCallSuper
Output getValue([ValuableContext? context = const ValuableContext()]) {
  // Check if the valuable is dependent of the ValuableContext to evaluate
  // If not, check if it's invalidation phase
  // If not, check for the cache to be provided
  // in that case, return cached value rather than reevaluate it
  if (!_evaluateWithContext &&
      !_reevaluatingNeeded &&
      valueCache.isProvided) {
    return valueCache.currentValue;
  }
  // Before reading/calculating the value, the watched Valuables tree is cleaned
  // in order to remove the dependencies that may disapear.
  cleanWatched();

  Output value = getValueDefinition(_reevaluatingNeeded, context);

  //
  if (!_evaluateWithContext) {
    valueCache.currentValue = value;
  }
  // We are reevaluating the Valuable, so we can unmark it
  _reevaluatingNeeded = false;
  // After we proceed to get the value, watched Valuables tree will be renewed
  return value;
}