Skip to content

Instantly share code, notes, and snippets.

@sccolbert
Created February 19, 2016 18:32
Show Gist options
  • Save sccolbert/76b1dc2de39ac92c6423 to your computer and use it in GitHub Desktop.
Save sccolbert/76b1dc2de39ac92c6423 to your computer and use it in GitHub Desktop.
interface ISlot<T, U> {
(sender: T, args: U): void;
}
class Signal<T, U> {
connect(slot: ISlot<T, U>): void {
}
disconnect(slot: ISlot<T, U>): void {
}
emit(sender: T, args: U): void {
}
}
// Example
class MyClass {
changed = new Signal<this, void>();
textChanged = new Signal<this, string>();
tabMoved = new Signal<this, { fromIndex: number, toIndex: number }>();
doThing(): void {
// ...
this.changed.emit(this, void 0);
}
setText(text: string): void {
// ...
this.textChanged.emit(this, text);
}
moveTab(fromIndex: number, toIndex: number) {
// ...
this.tabMoved.emit(this, { fromIndex }); // error - missing argument
this.tabMoved.emit(this, { fromIndex, toIndex });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment