Implement and recommend a DRYer approach #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi!
Thank you for your work. I am using this library, but in a wrapped manner because I found it to be verbose. I'd love to be able to use the library directly instead, sharing my recipe with others.
So this PR intends to add an alternative higher-level API, and document it as the recommended one.
What issues did I find with the original approach?
using-component
, as intended, goes in a per-route basis, which seems unnecessary. Why not give the whole system map to every request of every route? Else it's more code to write and more coupling to introduce (I have to remember to both add thisusing-component
clause in the routing part, and to fetch it later withuse-component
. If I change one part -> I have to update the other)use-component
is a glorifiedget
. If component keywords were directly associated to the request map, then I could leverage destructuring:(defn my-handler [{:keys [db sms worker] :as request}] ...)
If keyword clashes were a concern, developers could opt to use ns-qualified keywords instead of plain
:db
etc. I'd actually recommend that, but it should be each developer's choice.using-component
goes in the opposite direction, forcing safety at the cost of verbosity.Finally, the
app
/:app
thing in the README seems a good practice but also an unnecesary level of indirection in the context of learning a library. My changes respect:app
, but I would recommend to remove it, so:pedestal
depends directly on:db
(viacomponents-to-inject
).I hope this sounds like a reasonable changeset.
Cheers - Victor