bigBear713 / nb-common

Some common component, pipe, service based on angular.
https://bigbear713.github.io/nb-common/
MIT License
41 stars 6 forks source link

Provide an unsubscribe service #22

Closed bigBear713 closed 1 year ago

bigBear713 commented 1 year ago

version: v15.2.0

You know the combination of angular and rxjs is deeper, and unsubscribing is a regular thing to do, so we have to do it a lot。 We also know the DI in angular is so powerful, so I think here can provide an unsubscribe service to help us to do the thing, make it safer and more convenient.

bigBear713 commented 1 year ago

In component and directive, the service instancee should be destroyed and unsubscribe something when the component/directive is going to be destroyed.

Should easy to create or destroy the service instance, because sometimes we have to create or destroy it by ourselves,such as used in pipe.

Should provide a signal about the service instance is going to be destroied, so devr can unsubscribe by self. It will be more convenient if the service can unsubscribe the observer by self.

Can collect subscription by key, so devr can unsubcribe the one when need to. Devr can unsubscribe all subscriptions by themselves.

Can collect subscriptions quickly, sometimes we only want to collect them and unsubscribe them when the instance is going to destroyed.

bigBear713 commented 1 year ago

The properties: destroy$, subscriptionList and subscriptionMap can be set as protected, because it can make the service more flexible, devr can extend the service and overwrite the properties and method.

bigBear713 commented 1 year ago

It is provided in v16.0.0