Coder Social home page Coder Social logo

afshin / phosphor-disposable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from blink1073/phosphor-disposable

0.0 2.0 0.0 304 KB

A module for expressing the disposable object pattern.

License: BSD 3-Clause "New" or "Revised" License

Shell 6.52% TypeScript 93.48%

phosphor-disposable's Introduction

phosphor-disposable

Build Status Coverage Status

A module for expressing the disposable object pattern.

API Docs

Package Install

Prerequisites

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+

Bundle for the Browser

Follow the package install instructions first.

npm install --save-dev browserify
browserify myapp.js -o mybundle.js

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

phosphor-disposable's People

Contributors

sccolbert avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.