question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

  1. two-way binding and export message as “normal” JavaScript-friendly Object is not possible and sorry, but to me it is not usable, see https://github.com/grpc/grpc-web/issues/382#issuecomment-442005857
  2. dependency injection is not anyhow taken into account. Ideally every service client could become a native angular service
  3. 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).

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:36
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

13reactions
smnbbrvcommented, Nov 27, 2018

I gave up using it with angular for now. And the reasons are way bigger than the originally mentioned.

The show stopper for me is the inability to use two-way binding. The generated messages have a structure of Java-like setters / getters, while JavaScript has pure set / get attributes. That means all forms that are directly bound / mutating the message (at least template driven) are not usable anyhow. Angular material also mostly refers to the properties as names (see https://material.angular.io/components/table/overview table sorting and table filtering) and not as getters / setters.

A possible solution would be to use the toObject functionality (which is somehow implemented by https://github.com/improbable-eng/grpc-web), but it is not standardised in proto v3 and does not seem to appear. Even if the mentioned above was working, there is no fromObject functionality to cast it back.

This is all very sad. I was really looking forward to use gRPC because I am sick tired of translate-copy-pasting the interfaces but, well, the latter is way easier than using current gRPC implementations. There are too many limitations.

I update the original post with these thoughts as well.

5reactions
zaucycommented, Nov 26, 2018

I think it would be better suited to have a protoc plugin that supplies ‘deep’ support for angular instead of including it in this repository. There’s no end to the amount of frameworks that could incorporate gRPC Web. I think it would be unreasonable to keep support for these frameworks in this repository.

I have experimented with a plugin for angular support. All it does is wrap services into injectable angular services and wraps grpc-web’s calls to use Promises and Observables. However, it is only tested with improbable-eng’s implementation of gRPC Web. You can see it here: https://github.com/zaucy/protoc-gen-angular and it is also available as an npm package here: https://www.npmjs.com/package/@grpc-gen/protoc-gen-angular.

I plan on updating it in the future, but I have no timeline. I would happily accept pull requests or any kind of collaboration (in the form of a GitHub issue) from the community to make it more useable.

Side Node: the @grpc-gen organization is just a prefix so I don’t clog up any npm package names in case someone makes a fantastic protoc-gen-angular plugin before I do.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular versioning and releases
We update peer dependencies in minor versions by expanding the supported ... The following table provides the status for Angular versions under support....
Read more >
Angular
Release Released Active Support 15 1 month and 1 week ago. (16 Nov 2022) Ends in 4 months and 2 weeks. (18 May... 14 (...
Read more >
Angular (web framework)
Angular is a TypeScript-based, free and open-source web application framework led by the ... Key improvements in Angular 5 include support for progressive...
Read more >
Extended Long-term Support for AngularJS
The Benefits of Extended AngularJS Support ... Avoid significant time and development cost investments by keeping your existing application up to date and ......
Read more >
AngularJS Long-Term Support
OpenLogic provides long-term support for AngularJS, including security patches for high severity CVEs and fixes for web browser updates that cause breaking ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found