Last active
September 18, 2020 03:00
-
-
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/
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
// "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