Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

phosphor-disposable

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

phosphor-disposable

A module for expressing the disposable object pattern.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16
increased by433.33%
Maintainers
1
Weekly downloads
 
Created
Source

phosphor-disposable

A module for expressing the disposable object pattern.

API Docs

Package Install

Prerequisites

  • node
npm install --save phosphor-disposable

Source Build

Prerequisites

git clone https://github.com/phosphorjs/phosphor-disposable.git
cd phosphor-disposable
npm install

Rebuild

npm run clean
npm run build

Run Tests

Follow the source build instructions first.

npm test

Build Docs

Follow the source build instructions first.

npm run docs

Navigate to docs/index.html.

Supported Runtimes

The runtime versions which are currently known to work are listed below. Earlier versions may also work, but come with no guarantees.

  • Node 0.12.7+
  • IE 11+
  • Firefox 32+
  • Chrome 38+

Usage Examples

Note: This module is fully compatible with Node/Babel/ES6/ES5. Simply omit the type declarations when using a language other than TypeScript.

import {
  DisposableDelegate, DisposableSet, IDisposable
} from 'phosphor-disposable';


// Convert a function into a disposable.
var delegate = new DisposableDelegate(() => {
  console.log('disposed');
});

delegate.dispose();  // logs: 'disposed'
delegate.dispose();  // no-op


// Create a collection of disposables.
var d1 = new DisposableDelegate(() => {
  console.log('one');
});

var d2 = new DisposableDelegate(() => {
  console.log('two');
});

var d3 = new DisposableDelegate(() => {
  console.log('three');
});

var set = new DisposableSet([d1, d2, d3]);

set.dispose();  // logs: 'one', 'two', 'three'
set.dispose();  // no-op


// Create a custom disposable.
class MyDisposable implements IDisposable {

  constructor(id: string) {
    this._id = id;
  }

  get isDisposed(): boolean {
    return this._id === null;
  }

  dispose(): void {
    if (this._id !== null) {
      console.log(this._id);
      this._id = null;
    }
  }

  private _id: string;
}

var foo = new MyDisposable('foo');
var bar = new MyDisposable('bar');
var baz = new MyDisposable('baz');

var set = new DisposableSet();
set.add(foo);
set.add(bar);
set.add(baz);

set.dispose();  // logs: 'foo', 'bar', 'baz'
set.dispose();  // no-op

Keywords

FAQs

Package last updated on 26 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc