Created
February 19, 2016 18:32
-
-
Save sccolbert/76b1dc2de39ac92c6423 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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