0.7.0 • Published 6 years ago

ng-disposable v0.7.0

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

ng-disposable

Description

ng-disposable is a small library that lets you implement a disposable interface and add it to a list of services in order to tear down multiple services at once on a given condition.

Useful if you manage subscriptions or other state inside services that should be cleaned up simultanously e.g. on logout

Simply implement the Disposable interface and add the service to the DISPOSABLES injection token list using multi: true Then invoke the dispose function on the provided DisposableService

Usage

Implement the Disposable interface:

export class MyService implements Disposable {
  public dispose() {
    // tear down
  }
}

Add your disposable service to the module:

@NgModule({
  imports: [DisposableModule.forRoot()],
  providers: [
    MyService,
    {
      provide: DISPOABLES,
      useExisting: MyService,
      multi: true
    }
  ]
})
export class MyModule {}

use the DisposableService to tear down all disposables:

export class AppComponent {
  constructor(private service: DisposableService) {}

  public logout() {
    this.service.dispose();
  }
}

Contribute

0.7.0

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago