updateText method

  1. @override
void updateText(
  1. String text
)
override

Implementation

@override
void updateText(String text) {
  diff:
  if (node == null) {
    final toHydrate = parent!.toHydrate;
    if (toHydrate.isNotEmpty) {
      for (final e in toHydrate) {
        if (e.instanceOfString('Text')) {
          if (kVerboseMode) {
            print("Hydrate text node: $e");
          }
          node = e;
          if (e.textContent != text) {
            e.textContent = text;
            if (kVerboseMode) {
              print("Update text node: $text");
            }
          }
          toHydrate.remove(e);
          break diff;
        }
      }
    }

    node = web.Text(text);
    if (kVerboseMode) {
      print("Create text node: $text");
    }
  } else {
    if (!node.instanceOfString('Text')) {
      final elem = web.Text(text);
      (node as web.Element).replaceWith(elem as dynamic);
      node = elem;
      if (kVerboseMode) {
        print("Replace text node: $text");
      }
    } else {
      final node = this.node as web.Text;
      if (node.textContent != text) {
        node.textContent = text;
        if (kVerboseMode) {
          print("Update text node: $text");
        }
      }
    }
  }
}