Do we really want intermediate results? #3
woutermont
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Now that we have separated these first general handlers, we can start to hone them to perfection.
A first question I have about them, is why their methods need the intermediate results.
If their use case is to be able to
safeHandle
input, then I especially wonder why they are also included in the signatures ofcanHandle
andhandle
.The case of
safeHandle
itself is then a question of whether safe handling should be implemented this way.It is hardly any work for the calling code to write safe handling itself, given that they already possess the backup output. They can simply check the boolean output of
canHandle
and act accordingly:unsafeHandler.canHandle(input).pipe(mergeMap(handle => handle ? unsafeHandler.handle(input) : backup))
No need to pass the backup through an extra method.
If we really want to take even that little bit of code out of the way, it can be interesting too see that the
safeHandle
method itself actually behaves like aHandler
that takes anotherHandler
as dependency andcanHandle
everything. A cleaner (i.e. more concern-separated) way of providing safe handling might therefore be to provide aSafeHandler
wrapper:unsafeHandler.safeHandle(input, backup)
would then benew SafeHandler(unsafeHandler, backup).handle(input)
.Beta Was this translation helpful? Give feedback.
All reactions