Skip to content

Instantly share code, notes, and snippets.

@polotto
Last active November 10, 2018 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polotto/a90b2fbbb1921f8521554951213241cf to your computer and use it in GitHub Desktop.
Save polotto/a90b2fbbb1921f8521554951213241cf to your computer and use it in GitHub Desktop.
Simple way to implement the MVP pattern
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