update method

void update(
  1. TValue? updator(
    1. TValue value
    )
)

更新属性值

updator 指定值更新处理器 当 updator 处理器返回 null 时将不回写属性值

// example
BindableProperty.$value(initial: Item(x: 1, y: 1))
  .update((item) {
      if(item.x != 1) return null;
      item.x = 2;
      return item;
   });

Implementation

void update(TValue? Function(TValue value) updator) {
  var _oldValue = value, _newValue = updator(_oldValue);
  if (_newValue != null) {
    /// 如新值不为null,则表示需要发出变更通知
    ///
    /// - 当新值与旧值不同,则交由property内部处理是否发出通知
    /// - 否则强制发出变更通知
    ///
    if (_newValue != _oldValue)
      value = _newValue;
    else
      notify();
  }
}