notify method

void notify(
  1. T in_value, {
  2. bool? in_modify,
})

写入新值,发送通知

  • in_modify 强制指定是否发生了改变

Implementation

void notify(
  T in_value, {
  final bool? in_modify,
}) {
  _hasNotify = true;
  late final bool? f_modify;
  if (null != in_modify) {
    f_modify = in_modify;
  } else if (checkModify) {
    f_modify = (_value != in_value);
  } else {
    f_modify = null;
  }
  final oldValue = _value;
  _value = in_value;
  for (int i = 0; i < _listeners.length; ++i) {
    final item = _listeners[i];
    late final itemNotify =
        in_modify ?? item.hasModify?.call(oldValue, _value) ?? f_modify;
    if (false == itemNotify && item.onlyNotifyWhenModify) {
      // 未改变,且[item]要求仅当改变时通知,则跳过
      continue;
    }
    try {
      item.onActive(
        _value,
        itemNotify,
      );
    } catch (e) {
      MyLogger.to().severe(MyLogItem(
        prefix: "MyStream.notify Error",
        msg: [e.toString()],
      ));
    }
  }
}