-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: adds support for client generics, improving type safety in comb… #401
Open
Enngage
wants to merge
13
commits into
master
Choose a base branch
from
adding-client-generics
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d45a0e3
feat: adds support for client generics, improving type safety in comb…
Enngage e336716
Updates type naming, removes unused generics
Enngage 9a66547
Fixes more type names
Enngage c26915a
Simplifies default client types def
Enngage 4560adf
Adds support for types model in `linkedItems` (modular_content)
Enngage a952abd
Adds missing types for linked items models / mappers
Enngage 2377fc7
Merge branch 'master' into adding-client-generics
Enngage 3df48bd
Fixes & improvements based on review
Enngage 34bfe8f
feat: removes url-parse package in favor of native URL class
Enngage b022a12
updates deps
Enngage 7b9ee64
Only pass required generic arguments to mappers, mark item as possibl…
Enngage 5581c8e
chore(release): 16.0.0-0
Enngage 289dc1a
release (beta)
Enngage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import { ClientTypes } from '../models'; | ||
import { IDeliveryClientConfig } from '../config/delivery-configs'; | ||
import { DeliveryClient } from './delivery-client'; | ||
|
||
export function createDeliveryClient(config: IDeliveryClientConfig): DeliveryClient { | ||
export function createDeliveryClient<TClientTypes extends ClientTypes = ClientTypes>( | ||
config: IDeliveryClientConfig | ||
): DeliveryClient<TClientTypes> { | ||
return new DeliveryClient(config); | ||
} |
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this class doesn't need to send the whole type of object
TClientTypes
it just needs need type TClientTypes['contentItemType'].It would be easier to test this class if you need to pass only the necessary stuff
Check also the other classes for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't, the only reason I passed all types is for consistency and ease of use. Do you think it's worth splitting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand the point of ease of use, I am not sure about consistency. These generic types are new after all, so they are only consistent with the new code you are writing :).
For me there are two options:
contentItemType
. So for me as a tester of ElementMapper would be nice to pass justElementMapper<TContentItemType>
ElementMapper<TClientTypes extends Pick<ClientTypes, 'contentItemType'>>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me it seemed more straightforward to just pass the
TClientTypes
as a whole, but I changed it so the mappers now need only required generic arguments :)