onObservableChange method

dynamic onObservableChange(
  1. Observable? observable
)

Implementation

onObservableChange(Observable? observable)
{
  dynamic value = signature;

  // resolve all bindings
  Map<String?, dynamic>? variables;
  if ((bindings != null) && (scope != null))
  {
    for (Binding binding in bindings!)
    {
      dynamic v;

      // get binding source
      Observable? source = scope!.getObservable(binding, requestor: observable);
      if (source != null)
      {
        dynamic myValue = source.get();
        v = binding.translate(myValue);
      }

      // is this an eval?
      if (isEval)
      {
        variables ??= <String?, dynamic>{};
        if ((source is BlobObservable) && (!S.isNullOrEmpty(v)))
        {
          variables[binding.signature] = 'blob';
        }
        else
        {
          variables[binding.signature] = v;
        }
      }

      else if (this is! StringObservable && bindings!.length == 1 && signature != null && signature!.replaceFirst(binding.signature, "").trim().isEmpty)
      {
        value = v ?? source?.get();
        break;
      }

      // simple replacement of string values
      else
      {
        v = S.toStr(v) ?? "";
        value = value!.replaceAll(binding.signature, v);
      }
    }
  }

  // set the value
  value = (isEval) ? doEvaluation(signature, variables: variables) : value;

  // 2-way binding?
  if (observable?.twoway == this) value = observable!.value;

  // set the target value
  set(value);
}