observe方法

void observe(
  1. Node target,
  2. {bool? childList,
  3. bool? attributes,
  4. bool? characterData,
  5. bool? subtree,
  6. bool? attributeOldValue,
  7. bool? characterDataOldValue,
  8. List<String>? attributeFilter}
)

观察目标对象的特定变化。

对于可选参数的一些要求

  • childList, attributes或characterData中必须有一个为true。
  • 如果attributeOldValue为true,则attributes也必须为true。
  • 如果指定了attributeFilter,则attributes必须为true。
  • 如果characterDataOldValue为true,则characterData必须为true。

实现

void observe(Node target,
    {bool? childList,
    bool? attributes,
    bool? characterData,
    bool? subtree,
    bool? attributeOldValue,
    bool? characterDataOldValue,
    List<String>? attributeFilter}) {
  // Parse options into map of known type.
  var parsedOptions = _createDict();

  // Override options passed in the map with named optional arguments.
  override(key, value) {
    if (value != null) _add(parsedOptions, key, value);
  }

  override('childList', childList);
  override('attributes', attributes);
  override('characterData', characterData);
  override('subtree', subtree);
  override('attributeOldValue', attributeOldValue);
  override('characterDataOldValue', characterDataOldValue);
  if (attributeFilter != null) {
    override('attributeFilter', _fixupList(attributeFilter));
  }

  _call(target, parsedOptions);
}