Skip to content

Instantly share code, notes, and snippets.

@ripla
Created May 16, 2014 18:03
Show Gist options
  • Save ripla/9ee0c86af02f18564665 to your computer and use it in GitHub Desktop.
Save ripla/9ee0c86af02f18564665 to your computer and use it in GitHub Desktop.
Quick draft of View-Presenter injection with the cake pattern
trait SomeView {
def render(): Unit
def init(): Unit
}
trait SomeViewComponent {
this: SomePresenterComponent =>
val someView: SomeView
class SomeViewImpl extends SomeView {
presenter.view = this
def render() = Console.println("Rendering!")
def init() = presenter.init()
}
}
trait SomePresenterComponent {
val presenter: SomePresenter
class SomePresenter {
var view: SomeView = _
def init() = view.render()
}
}
class ComponentRegistry extends SomePresenterComponent with SomeViewComponent {
val presenter = new SomePresenter()
val someView = new SomeViewImpl()
}
val view = new ComponentRegistry().someView
view.init()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment