georgipeltekov / ngx-file-drop

Angular 11 file and folder drop library
MIT License
296 stars 101 forks source link

dropEventTimerSubscription: late unsubscription #260

Open LeoNiedermeier opened 2 years ago

LeoNiedermeier commented 2 years ago

Related to https://github.com/georgipeltekov/ngx-file-drop/issues/224

The dropEventTimerSubscription is not unsubscribed after dropped finished. It is still there and fires until the next drop event or the component is destroyed. This has the side effect that the angular change detection also runs every 200ms.

Maybe with a code like the following insteded of just using numOfActiveReadEntries--, the dropEventTimer in https://github.com/georgipeltekov/ngx-file-drop/blob/b63662c3b233376d929c1c073a820f0b045bfc4b/src/ngx-file-drop/ngx-file-drop.component.ts#L225 is not necessary anymore:

  decrementNumOfActiveReadEntries () {
    this.numOfActiveReadEntries --;

    if (this.numOfActiveReadEntries == 0) {
      this.zone.run(() =>
       const files = this.files;
        this.files = [];
        this.onFileDrop.emit(files);
    }
  }
elruss commented 6 months ago

Is there a workaround for this? We use Angular's built-in testability object for QA, and the timer is preventing that object from stabilizing after a file drop.