bindWith<T> method

void bindWith<T>({
  1. NDSubject? subject,
  2. NDKeys? keys,
  3. T? context,
  4. void binder0()?,
  5. void binder1(
    1. NDKeys keys
    )?,
  6. void binder2(
    1. NDKeys keys,
    2. T? dataContext
    )?,
  7. void binder3(
    1. NDSubject subject,
    2. NDKeys keys,
    3. T? dataContext
    )?,
})

Implementation

void bindWith<T>({
  NDSubject? subject,
  NDKeys? keys,
  T? context,
  void Function()? binder0,
  void Function(
    NDKeys keys,
  )?
      binder1,
  void Function(
    NDKeys keys,
    T? dataContext,
  )?
      binder2,
  void Function(
    NDSubject subject,
    NDKeys keys,
    T? dataContext,
  )?
      binder3,
}) {
  if (subject == null || keys == null) {
    _handle.value = null;
    return;
  }

  NDCallback? callback;
  if (binder0 != null) {
    callback = (_) => binder0();
  } else if (binder1 != null) {
    callback = binder1;
  } else if (binder2 != null) {
    callback = (keys) => binder2(keys, context);
  } else if (binder3 != null) {
    callback = (keys) => binder3(subject, keys, context);
  }

  if (callback == null) {
    _handle.value = null;
    return;
  }

  _handle.value = subject.bind(keys, callback);
}