Add Emitter.clear() and DisposableStatic.isDisposable() (#12472)

This commit is contained in:
Glen M 2016-11-13 04:45:21 -05:00 committed by Masahiro Wakame
parent 4d7168f75d
commit efb5680468
2 changed files with 13 additions and 0 deletions

View File

@ -24,6 +24,7 @@ class User {
}
destroy(): void {
this.emitter.clear();
this.emitter.dispose();
}
}
@ -39,6 +40,7 @@ var user = new User();
var subscription = user.onDidChangeName((name: string) => {
console.log('User name change to: ' + name);
});
if(Disposable.isDisposable(subscription)) {}
subscription.dispose();
// CompositeDisposable

11
event-kit/index.d.ts vendored
View File

@ -14,6 +14,10 @@ declare namespace AtomEventKit {
interface DisposableStatic {
prototype: Disposable;
new (disposalAction: Function): Disposable;
/**
* Ensure that Object correctly implements the Disposable.
*/
isDisposable(object: Object): boolean;
}
/** Instance side of the Disposable class. */
@ -59,6 +63,13 @@ declare namespace AtomEventKit {
isDisposed: boolean;
constructor: EmitterStatic;
/**
* Clear out any existing subscribers.
*/
clear(): void;
/**
* Unsubscribe all handlers.
*/
dispose(): void;
/**
* Registers a handler to be invoked whenever the given event is emitted.