Created
August 28, 2014 12:31
-
-
Save Evgenus/4b6f5c0e5a12f2a6145f to your computer and use it in GitHub Desktop.
Cross mixin references
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
class EventEmitter { | |
public fire(): void { | |
} | |
} | |
//----------------------------------------------------------------- | |
interface ICanFire { | |
fire(): void; | |
} | |
interface IModel { | |
do(): void; | |
} | |
class Model { | |
private _emitter: ICanFire; | |
constructor(emitter: ICanFire) { | |
this._emitter = emitter; | |
} | |
do() { | |
this._emitter.fire(); | |
} | |
} | |
//----------------------------------------------------------------- | |
interface AppApi extends EventEmitter, IModel { | |
} | |
class App { | |
private _emitter: EventEmitter; | |
private _model: Model; | |
constructor() { | |
this._emitter = new EventEmitter(); | |
this._model = new Model(this._emitter); | |
} | |
public getApi(): AppApi { | |
return { | |
fire: this._emitter.fire.bind(this._emitter), | |
do: this._model.do.bind(this._model), | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment