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 replacementValue;

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

      // is this an eval?
      if (isEval) {
        variables ??= <String?, dynamic>{};
        if ((source is BlobObservable) &&
            (!isNullOrEmpty(replacementValue))) {
          variables[binding.signature] = 'blob';
        } else {
          variables[binding.signature] = replacementValue;
        }
      } else if (this is! StringObservable &&
          bindings!.length == 1 &&
          signature != null &&
          signature!.replaceFirst(binding.signature, "").trim().isEmpty) {
        value = replacementValue ?? source?.get();
        break;
      }

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

  // perform the evaluation
  if (isEval) {
    value = doEvaluation(signature, variables: variables);
  }

  // 2-way binding?
  if (observable?.twoway == this) {
    set(observable!.value, setter: observable);
  }

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