-
Notifications
You must be signed in to change notification settings - Fork 1
Repurpose DataSource/Repository
base interface to DataSource<T>/Repository<T>
get/put/delete type aliases
#88
Comments
@doup I've never seen the need of generate a repository as a generic one like you're proposing. The provider defines the specific repository that is being used. Could you show an example of this need? |
@doup we only have it in harmony-swift because it allows us to not provide the 3 different repositories or data sources in the constructor thanks to a swift generic feature. Here you have an example of being used in harmony-swift in the cache repository. We are providing one instance type for the main and another for the cache datasources. As we can't do it on kotlin, we do not have that interface created in harmony-kotlin. I would suggest removing the interface from the code base as it's not useful. |
I suggest we repurpose it to the following: type DataSource<T> = GetDataSource<T> & PutDataSource<T> & DeleteDataSource;
type Repository<T> = GetRepository<T> & PutRepository<T> & DeleteRepository; In a provider, instead of using a concrete type (e.g. @orioljp this is an example: c004ebd
I think the second option is the correct one. If we repurpose |
Btw, we could also add the following helper types (same applies for
So we would have:
|
The type for the Nevertheless, applying the same concept for all types of combinations is overkill, and it's already complex to explain things to the team, so adding more wrapper types will be more confusing. |
Repository
interface?DataSource/Repository
base interface to DataSource<T>/Repository<T>
get/put/delete type aliases
Sorry for joining late. Only after getting notified about the PR, I've noticed the discussion. It bothers me that only the case that implements all is contemplated. What if we do something like ?
|
@lucianosantana @joselufo I don't think this is a good idea. I see two problems:
How were you thinking to use this union type? As an alternative, maybe we can reconsider the addition of these?
|
For the record, I've discussed with @doup and the "catch all" union type wouldn't be really helpful, as it gives no assurance about the expected methods to be implemented, forcing us to do some narrowing to use it. The motivation for my suggestion was that I find confusing using the name "Repository" only for the case that implements all 3 types of Repository. While, for example, a PutRepository in this case wouldn't be of type Repository. But we actually have this pattern in other places. The alternative would be to write union specific types, without any wrapper type. But this would be too verbose and less efficient. So in the end, I'm convinced to use it this way to be consistent with the rest of the code base. |
See agreed proposal: #88 (comment)
Original Message:
We have an empty base
Repository
interface which all three repositories implement. On a provider is not very useful as the generic interactors will complain that the provided repository doesn't implement the interface… so something like this doesn't work:Instead, we need to do this:
Do we really need
Repository
?Maybe we need some helper types that join these? Something like:
GetPutRepository<MyModel>
,FullRepository<MyModel>
…The text was updated successfully, but these errors were encountered: