Last active
November 10, 2018 18:13
-
-
Save polotto/a90b2fbbb1921f8521554951213241cf to your computer and use it in GitHub Desktop.
Simple way to implement the MVP pattern
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 BaseContract { | |
showProgress() | |
hideProgress() | |
} | |
interface Contract extends BaseContract { | |
interface View { | |
populate(models: [Model]) | |
} | |
interface Service { | |
load() | |
} | |
} | |
class Activity implements Contract.View { | |
presenter: Presenter | |
onCreate() { | |
this.presenter = Presenter(this) | |
} | |
onResume() { | |
this.presenter.load() | |
} | |
populate(models: [Model]) { | |
// popula a lista | |
} | |
} | |
class Presenter implements Contract.Service { | |
view: Contract.View | |
constructor(view: Contract.View) { | |
this.view = view | |
} | |
load() { | |
this.view.showProgress() | |
// carrega | |
this.view.hideProgress() | |
this.view.populate(models) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment