feat: allow client to be extended with custom controllers #240
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.
Description
EdcConnectorClient
is now able to be extended by providing a customEdcController
implementation when building it.For this purpose,
EdcConnectorClient.Builder
has a new methoduse
which takes a string property name as first argument and aEdcController
class as second./cc @psalmry @selimbens
Closes #213
How to test it
Approach
In the first place, this PR adds a new class:
EdcController
.EdcController
is a base implementation of a controller, which defines:inner
andcontext
fields the controller exposesThis class is necessary for defining a common base type and ensure type safety; as controllers will be lazily instanciated, we need a shared interface.
Having a base class it allows us to implement the middleware-like extension. So, the client's
Builder
class now include ause
method, which takes a property name and aEdcController
-extended class, adding it to the instance upon build.With the new controller class and builder method, it is now possible to extend the
EdcConnectorClient
as showed above in the "How to test it" sectionOpen Questions
Types' ergonomics
Currently the library exports
EdcConnectorClient
class and theEdcConnectorClientType<T>
. The latter one allows us to define typings for an extended client.I'm wondering if it would make sense to rename these types to be more elegant (yeah, very subjective 😅).
EdcConnectorClient
->Client
EdcConnectorContext
->Context
EdcConnectorClientType<T>
->EdcConnectorClient<T>
This change would be a breaking change though - which is not too bad, as we are still pre-1.0.0, but still a bit of a pain.
Nevertheless, this update should be part of a follow up PR.