add method
T?
add(
- T data
发射数据
Implementation
T? add(T data) {
if (_subject.isClosed) {
L.w('[$_semantics]IO在close状态下请求发送数据');
return null;
}
if (isEmpty(data) && !_acceptEmpty) {
if (_printLog) {
L.w('[$_semantics]转发被拒绝! 原因: 需要非Empty值, 但是接收到Empty值');
}
return data;
}
// 如果需要distinct的话, 就判断是否相同; 如果不需要distinct, 直接发射数据
if (_isDistinct) {
// 如果是不一样的数据, 才发射新的通知,防止TabBar的addListener那种
// 不停地发送通知(但是值又是一样)的情况
if (!_isSame(data, latest)) {
if (_printLog) L.d('IO转发出[$_semantics]数据: $data');
_subject.add(data);
} else {
if (_printLog) {
L.w('[$_semantics]转发被拒绝! 原因: 需要唯一, 但是新数据 ($data) 与最新值 ($latest) 相同');
}
}
} else {
if (_printLog) L.d('IO转发出[$_semantics]数据: $data');
_subject.add(data);
}
return data;
}