When extending from Angular services, it is handy to re-use some properties (eg. resourceUrl) as well as some helper methods (eg. convertDateFromServer or convertDateArrayFromServer. Unfortunatelly these are private. Making properties and helper methods protected would ease inheritance.
As explained in the talk I gave on JHipster we tend to not change the JHipster code, but instead, inherit from it. Having resourceUrl, convertDateFromServer, convertDateArrayFromServer protected would ease inheritance. For example, this is what we would be able to do:
This is the generated code from JHispter for an Angular service (notice resourceUrl is protected instead of private):
@Injectable({ providedIn: 'root' })
export class BoothService {
protected resourceUrl = SERVER_API_URL + 'api/booths';
constructor(private http: HttpClient) {}
create(booth: IBooth): Observable<EntityResponseType> {
return this.http.post<IBooth>(this.resourceUrl, booth, { observe: 'response' });
}
...
This is our own service that extends the previous one (it now uses resourceUrl):
@Injectable({ providedIn: 'root' })
export class SponsoringBoothService extends BoothService {
constructor(private httpClient: HttpClient) {
super(httpClient);
}
queryAvailableBooth(sponsorLevelId: number, eventId: number): Observable<EntityArrayResponseType> {
return this.httpClient.get<IBooth[]>(`${this.resourceUrl}?sponsorLevelId.equals=${sponsorLevelId}&eventId.equals=${eventId}`, { observe: 'response' });
}
}
As you can see, we re-use ${this.resourceUrl}. But this is only doable if we change the generated BoothService, which we don't want to do.
LGTM, we can even make them public, I don't know why those informations would need to be private for the class.
I think it should be fine. Would you mind doing a PR since its a minor
change
On Tue, 9 Oct 2018, 1:43 pm Antonio Goncalves, notifications@github.com
wrote:
Overview of the feature request
When extending from Angular services, it is handy to re-use the
resourceUrl property. Unfortunatelly it is private. Making it protected
would ease inheritance
Motivation for or Use CaseAs explained in the talk I gave on JHipster
https://www.youtube.com/watch?v=9WVpwIUEty0 we tend to not change the
JHipster code, but instead, inherit from it. Having resourceUrl property
protected, this is what we would be able to do:This is the generated code from JHispter for an Angular service:
@Injectable({ providedIn: 'root' })
export class BoothService {
protected resourceUrl = SERVER_API_URL + 'api/booths';constructor(private http: HttpClient) {} create(booth: IBooth): Observable<EntityResponseType> { return this.http.post<IBooth>(this.resourceUrl, booth, { observe: 'response' }); }...
This is our own service that extends the previous one:
@Injectable({ providedIn: 'root' })
export class SponsoringBoothService extends BoothService {constructor(private httpClient: HttpClient) { super(httpClient); } queryAvailableBooth(sponsorLevelId: number, eventId: number): Observable<EntityArrayResponseType> { return this.httpClient.get<IBooth[]>(`${this.resourceUrl}?sponsorLevelId.equals=${sponsorLevelId}&eventId.equals=${eventId}`, { observe: 'response' }); }}
As you can see, we re-use ${this.resourceUrl}. But this is only doable if
we change the generated BoothService, which we don't want to do.
- Checking this box is mandatory (this is just to show you read
everything)—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/jhipster/generator-jhipster/issues/8509, or mute the
thread
https://github.com/notifications/unsubscribe-auth/ABDlF9z2jbs00ocdaNOWAV_O49Fz1AxQks5ujIvggaJpZM4XTCKX
.
@deepu105 If you promise that @jdubois will not close this issue in a couple of weeks but rather leave me some time (after Voxxed Microservices) then it will be a pleasure for me to do this PR ;o) You can assign it to me
Ha ha ha, I can't promise on Julien's behalf as he really doesn't like long
standing issues. But I can try to do this this week for you :)
On Tue, 9 Oct 2018, 8:07 pm Antonio Goncalves, notifications@github.com
wrote:
@deepu105 https://github.com/deepu105 If you promise that @jdubois
https://github.com/jdubois will not close this issue in a couple of
weeks but rather leave me some time (after Voxxed Microservices) then it
will be a pleasure for me to do this PR ;o) You can assign it to me—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/jhipster/generator-jhipster/issues/8509#issuecomment-428292529,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABDlF0OiPCNm1EPyP-3jc8O8LOczp07Bks5ujOXOgaJpZM4XTCKX
.
@deepu105 just upgraded to JHipster 5.5.0. resourceUrl is now public but convertDateFromClient or convertDateFromServer are still private. Any reason why ?
@agoncal no specific reason, you didn't ask for them that's the real reason :wink:
Originally I thought they might not be needed out side those services but ya no harm in making them public, its JS in the end anyway
if there is any other such methods that you want to be public, can you let me know, i'll make the change
@deepu105 I did ask for them ;o)
For now that's the only two methods that we need to extend. Can't see any other.
Thanks
Oh sorry, I missed it somehow
On Fri, 19 Oct 2018, 7:55 am Antonio Goncalves, notifications@github.com
wrote:
@deepu105 https://github.com/deepu105 I did ask for them
https://github.com/jhipster/generator-jhipster/issues/8509#issue-368169094
;o)For now that's the only two methods that we need to extend. Can't see any
other.Thanks
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/jhipster/generator-jhipster/issues/8509#issuecomment-431253065,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABDlF-h7cX-SjsbpnKlASWVAcvU2aj4Tks5umWlrgaJpZM4XTCKX
.
@agoncal done
Most helpful comment
Ha ha ha, I can't promise on Julien's behalf as he really doesn't like long
standing issues. But I can try to do this this week for you :)
On Tue, 9 Oct 2018, 8:07 pm Antonio Goncalves, notifications@github.com
wrote: