appendCallback method

void appendCallback({
  1. EventCallbackAdd<CallbackDataT>? onAdd,
  2. EventCallbackRemove<CallbackDataT>? onRemove,
  3. EventCallbackCall<CallbackDataT>? onCall,
  4. EventCallbackCancel<CallbackDataT>? onCancel,
})

Implementation

void appendCallback({
  EventCallbackAdd<CallbackDataT>? onAdd,
  EventCallbackRemove<CallbackDataT>? onRemove,
  EventCallbackCall<CallbackDataT>? onCall,
  EventCallbackCancel<CallbackDataT>? onCancel,
}) {
  if (onAdd != null) {
    final oldAdd = this.onAdd;
    this.onAdd = (EventEmitter emitter) {
      oldAdd?.call(emitter);
      onAdd.call(emitter);
    };
  }

  if (onRemove != null) {
    final oldRemove = this.onRemove;
    this.onRemove = (EventEmitter emitter) {
      oldRemove?.call(emitter);
      onRemove.call(emitter);
    };
  }

  if (onCall != null) {
    final oldCall = this.onCall;
    this.onCall = (CallbackDataT data) {
      oldCall?.call(data);
      onCall.call(data);
    };
  }

  if (onCancel != null) {
    final oldCancel = this.onCancel;
    this.onCancel = () {
      oldCancel?.call();
      onCancel.call();
    };
  }
}