Disposable

A handle to a resource that can be disposed. You can use it by requiring event-kit module.

import { Disposable } from 'event-kit'

constructor(disposalAction)

Construction

Construct a Disposable

Parameters

  • Name
    disposalAction
    Type
    (() => void) | undefined
    Required
    Description

    A Function to call when .dispose() is called for the first time.

Example

const disposable = new Disposable(() => this.destroyResource())

dispose()

Destruction

Perform the disposal action, indicating that the resource associated with this disposable is no longer needed. You can call this method more than once, but the disposal action will only be performed the first time.

Example

disposable.dispose();

Disposable.isDisposable(object)

Check if disposable

Ensure that object correctly implements the Disposable contract.

Parameters

  • Name
    object
    Type
    object
    Required
    Description

    A object.

Return value

Returns a Boolean indicating whether object is a valid Disposable.

Example

class ExampleDisposable {
    dispose() {
        // ...
    }
}
Disposable.isDisposable(new ExampleDisposable());
Can you help us improve the docs? 🙏

The source of these docs is here on GitHub. If you see a way these docs can be improved, please fork us!