Skip to content

Instantly share code, notes, and snippets.

@patroza
Last active September 18, 2020 03:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patroza/213bfd32e8efcd63ddb07975082db8d1 to your computer and use it in GitHub Desktop.
Save patroza/213bfd32e8efcd63ddb07975082db8d1 to your computer and use it in GitHub Desktop.
Literal Controller/Presenter/Interactor implementation sample (naive), I prefer MediatR instead for most cases :) from http://www.plainionist.net/Implementing-Clean-Architecture-Controller-Presenter/
// "controller"
(ctx, next) => {
let presenter = new Presenter(ctx)
let interactor = new Interactor(presenter)
interactor.handle(getRequestFrom(ctx))
}
class Presenter {
constructor(ctx) { this.ctx = ctx }
present(response) {
let viewModel = responseToViewModel(response)
ctx.Body = JSONSerialize(viewModel)
ctx.Status = 200
}
}
class Interactor {
constructor(presenter) { this.presenter = presenter }
handle(request) {
// do stuff
let response = ...
this.presenter.present(response)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment