-
Notifications
You must be signed in to change notification settings - Fork 790
Description
Hi guys,
it would be really nice to have a deep Angular support.
One can say it is supported, and, well, one can use it with Angular. However, it currently feels like an alien bird in the nest because
- two-way binding and export message as "normal" JavaScript-friendly Object is not possible and sorry, but to me it is not usable, see Angular support #382 (comment)
- dependency injection is not anyhow taken into account. Ideally every service client could become a native angular service
- the methods are not compatible with neither RX Observables / native Promises. With Promise it is quite clear it cannot be supported because of non-unary methods, but RX is fully compliant here.
This is what I came to after a couple of attempts
export function fromClient<T>(c: T) {
return <any>autoBind(<any>c) as T;
}
export function fromUnary<T extends Message>(clientMethod: (...p) => UnaryResponse, request: Message, meta?: Metadata) {
return new Observable<T>(obs => {
const req = clientMethod(request || null, meta || null, (err: ServiceError, response: T) => {
if (err) {
obs.error(err);
}
obs.next(response);
obs.complete();
});
return () => req.cancel();
});
}
and usage:
const client = fromClient(new HelloServiceClient(environment.grpc));
const obs = fromUnary<Hello>(client.getHello, new HelloRequest());
This code is far away from ideal. It is actually ugly, because I need to monkey-bind the methods and status is not returned anyhow yet (however the status part is quite solvable with pipe > filter and some boolean parameter in observable response).
Finally, the question: do you plan to support Angular in this / related repository? Should @angular/cli care of this instead? Or it is up to the end user to decide how to solve this problem?
I am ready to participate / support here (if possible).