Skip to content

Conversation

@shimks
Copy link
Contributor

@shimks shimks commented Apr 2, 2018

Checklist

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in packages/example-* were updated

@shimks shimks changed the title Get repository [WIP] feat(repository): add getRepository function to mixin Apr 2, 2018
@shimks shimks changed the title [WIP] feat(repository): add getRepository function to mixin feat(repository): add getRepository function to mixin Apr 2, 2018
* @param repo The repository class to retrieve the instance of
*/
// tslint:disable-next-line:no-any
async getRepository<Repo extends Repository<any>>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we have to use any for the type, I'd prefer to be a bit more restrictive and put {}

Copy link
Contributor Author

@shimks shimks Apr 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't do that since the generic used here needs to be restricted to Model. The reasoning behind using any was just to replicate style seen in other code, but I'll see if there's a better reason for it.

BTW, if we were to change any with Model, that would require Model type to be imported every time RepositoryMixin is used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay then I'm for using Model here and fine with it being imported as RepositoryMixin is used. My reason being VS code intelliSense would be able to figure it out and we already have to import juggler and DataSourceConstructor etc. for RepositoryMixin anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does mean that the scope of this PR would get much larger since I'd have to go into the docs to make sure that the imports are there. @strongloop/lb-next-dev thoughts before I make this change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah on that note, if this is something we're doing in our codebase already (losing type safety because of any), we can create an issue to track it and address it separately.

Copy link
Contributor

@b-admike b-admike left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

Copy link
Contributor

@virkt25 virkt25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the AppWithRepository interface with the getRepository function please.

@shimks
Copy link
Contributor Author

shimks commented Apr 5, 2018

@virkt25 Should I also update AppWithRepository with other sugar functions in the mixin?

@virkt25
Copy link
Contributor

virkt25 commented Apr 5, 2018

Yes please! :) I think the only other one is datasource.

* @param repo The repository class to retrieve the instance of
*/
// tslint:disable-next-line:no-any
async getRepository<Repo extends Repository<any>>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider using R instead of Repo for the generic variable? I went looking for the Repo type not realizing it was a generic like T.

-- Maybe it's just me, but I expect to see generics as one capital letter. Usually T but that's taken in this case so R might make sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'll take a look around in the codebase to see how people named their generics.

Copy link
Contributor

@virkt25 virkt25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one comment about variable name choice. I don't think we have guidelines around it but I haven't see a full name used for a generic variable in our code base.

@shimks shimks merged commit 6e1be1f into master Apr 5, 2018
@shimks shimks deleted the get-repository branch April 5, 2018 17:43
@shimks shimks removed the review label Apr 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants