Skip to content

API > @blocksuite/lit > WithDisposable

Function: WithDisposable ​

WithDisposable<T>(SuperClass): T & Constructor< DisposableClass >

Mixin that adds a _disposables: DisposableGroup property to the class.

The _disposables property is initialized in connectedCallback and disposed in disconnectedCallback.

see https://lit.dev/docs/composition/mixins/

Type parameters ​

Parameter
T extends Constructor< LitElement >

Parameters ​

ParameterType
SuperClassT

Returns ​

T & Constructor< DisposableClass >

Example ​

ts
class MyElement extends WithDisposable(ShadowlessElement) {
  onClick() {
    this._disposables.add(...);
  }
}
class MyElement extends WithDisposable(ShadowlessElement) {
  onClick() {
    this._disposables.add(...);
  }
}

Defined In ​

packages/lit/src/with-disposable.ts:30