Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Expose array instance #10

Open
wSedlacek opened this issue Jun 19, 2020 · 0 comments
Open

Feature Request: Expose array instance #10

wSedlacek opened this issue Jun 19, 2020 · 0 comments

Comments

@wSedlacek
Copy link

So recently I have been attempting to find a simple pattern for unsubscribing. I really am enjoying SubSink however I still need to do a whole ngOnDestory() when using it.

I have looked into a few other libraries and the one I have come across that I have found with the best patterns for removing ngOnDestory() has been the @ngneat/until-destroy library. However it's patterns for tracking observables is a bit cumbersome.

So I had the idea of using subsink with @ngneat/until-destroy. @ngneat/until-destroy offers the option to provide the name of a Subscription array member and it will unsubscribe when the component is destroyed. However SubSink stores it's array internally so I thought instead we could do something like this -

class SubSink extends Array<SubscriptionLike>

Given that SubSink has no methods that overlap with an Array this change can be non breaking and allow for this pattern.

@UntilDestroy({ arrayName: "subs" })
@Directive({
  selector: "[appGrid]"
})
export class GridDirective implements AfterContentInit {
  @ContentChildren(GridItemDirective)
  private readonly items: QueryList<GridItemDirective>;

  private readonly subs = new SubSink();
  private flipping = new Flipping();

  public notifyChange() {
    this.flipping.read();
  }

  public ngAfterContentInit() {
    this.subs.sink = this.items.changes.subscribe(() => {
      this.flipping.flip();
    });
  }
}

As it stands right now if I wanted to use this pattern with SubSink I would need to provide UntilDestory with the private reference to subs._subs which I feel is somewhat of an Anti-pattern.

What are your thoughts @wardbell?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant